Why does the URI constructor remove part of path from the baseUri argument?
public class Program
{
public static void Main()
{
Uri baseUri = new Uri("http://localhost:7777/BasePath/");
Uri uri = new Uri(baseUri, "/controller");
Console.WriteLine(uri);
}
}
Is it the intend behavior to wipe /BasePath out from uri and the final result be http://localhost:7777/controller
?
c# uri
add a comment |
public class Program
{
public static void Main()
{
Uri baseUri = new Uri("http://localhost:7777/BasePath/");
Uri uri = new Uri(baseUri, "/controller");
Console.WriteLine(uri);
}
}
Is it the intend behavior to wipe /BasePath out from uri and the final result be http://localhost:7777/controller
?
c# uri
Because the/
in/controller
indicates "from root" where root ishttp://localhost:7777
.
– Sani Singh Huttunen
Nov 13 '18 at 17:09
You need to donew Uri(baseUri, "./controller")
to state that your path is relative from the current path (denoted by the dot). This will returnhttp://localhost:7777/BasePath/controller
.
– ckuri
Nov 13 '18 at 18:21
Or keep yourbaseUri
and yourrelativeUri
separate.Uri baseUri = new Uri("http://localhost:7777"); Uri uri = new Uri(baseUri, "/BasePath/controller");
That way there's nothing to accidentally overwrite.
– Scott Hannen
Nov 13 '18 at 19:01
add a comment |
public class Program
{
public static void Main()
{
Uri baseUri = new Uri("http://localhost:7777/BasePath/");
Uri uri = new Uri(baseUri, "/controller");
Console.WriteLine(uri);
}
}
Is it the intend behavior to wipe /BasePath out from uri and the final result be http://localhost:7777/controller
?
c# uri
public class Program
{
public static void Main()
{
Uri baseUri = new Uri("http://localhost:7777/BasePath/");
Uri uri = new Uri(baseUri, "/controller");
Console.WriteLine(uri);
}
}
Is it the intend behavior to wipe /BasePath out from uri and the final result be http://localhost:7777/controller
?
c# uri
c# uri
edited Nov 13 '18 at 17:14
Scott Hannen
12.7k1425
12.7k1425
asked Nov 13 '18 at 17:08
Junior MJunior M
10k2497153
10k2497153
Because the/
in/controller
indicates "from root" where root ishttp://localhost:7777
.
– Sani Singh Huttunen
Nov 13 '18 at 17:09
You need to donew Uri(baseUri, "./controller")
to state that your path is relative from the current path (denoted by the dot). This will returnhttp://localhost:7777/BasePath/controller
.
– ckuri
Nov 13 '18 at 18:21
Or keep yourbaseUri
and yourrelativeUri
separate.Uri baseUri = new Uri("http://localhost:7777"); Uri uri = new Uri(baseUri, "/BasePath/controller");
That way there's nothing to accidentally overwrite.
– Scott Hannen
Nov 13 '18 at 19:01
add a comment |
Because the/
in/controller
indicates "from root" where root ishttp://localhost:7777
.
– Sani Singh Huttunen
Nov 13 '18 at 17:09
You need to donew Uri(baseUri, "./controller")
to state that your path is relative from the current path (denoted by the dot). This will returnhttp://localhost:7777/BasePath/controller
.
– ckuri
Nov 13 '18 at 18:21
Or keep yourbaseUri
and yourrelativeUri
separate.Uri baseUri = new Uri("http://localhost:7777"); Uri uri = new Uri(baseUri, "/BasePath/controller");
That way there's nothing to accidentally overwrite.
– Scott Hannen
Nov 13 '18 at 19:01
Because the
/
in /controller
indicates "from root" where root is http://localhost:7777
.– Sani Singh Huttunen
Nov 13 '18 at 17:09
Because the
/
in /controller
indicates "from root" where root is http://localhost:7777
.– Sani Singh Huttunen
Nov 13 '18 at 17:09
You need to do
new Uri(baseUri, "./controller")
to state that your path is relative from the current path (denoted by the dot). This will return http://localhost:7777/BasePath/controller
.– ckuri
Nov 13 '18 at 18:21
You need to do
new Uri(baseUri, "./controller")
to state that your path is relative from the current path (denoted by the dot). This will return http://localhost:7777/BasePath/controller
.– ckuri
Nov 13 '18 at 18:21
Or keep your
baseUri
and your relativeUri
separate. Uri baseUri = new Uri("http://localhost:7777"); Uri uri = new Uri(baseUri, "/BasePath/controller");
That way there's nothing to accidentally overwrite.– Scott Hannen
Nov 13 '18 at 19:01
Or keep your
baseUri
and your relativeUri
separate. Uri baseUri = new Uri("http://localhost:7777"); Uri uri = new Uri(baseUri, "/BasePath/controller");
That way there's nothing to accidentally overwrite.– Scott Hannen
Nov 13 '18 at 19:01
add a comment |
1 Answer
1
active
oldest
votes
I had to dig into the documentation for the constructor you're calling.
public Uri (Uri baseUri, string relativeUri);
Additionally, if the
relativeUri
begins with a slash, then it will replace any relative part of thebaseUri
.
It's the intended behavior. If you specify a relative path that begins with a slash, it assumes that the relative path is the entire relative path, so it discards any relative path already included in baseUri
.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53286212%2fwhy-does-the-uri-constructor-remove-part-of-path-from-the-baseuri-argument%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
I had to dig into the documentation for the constructor you're calling.
public Uri (Uri baseUri, string relativeUri);
Additionally, if the
relativeUri
begins with a slash, then it will replace any relative part of thebaseUri
.
It's the intended behavior. If you specify a relative path that begins with a slash, it assumes that the relative path is the entire relative path, so it discards any relative path already included in baseUri
.
add a comment |
I had to dig into the documentation for the constructor you're calling.
public Uri (Uri baseUri, string relativeUri);
Additionally, if the
relativeUri
begins with a slash, then it will replace any relative part of thebaseUri
.
It's the intended behavior. If you specify a relative path that begins with a slash, it assumes that the relative path is the entire relative path, so it discards any relative path already included in baseUri
.
add a comment |
I had to dig into the documentation for the constructor you're calling.
public Uri (Uri baseUri, string relativeUri);
Additionally, if the
relativeUri
begins with a slash, then it will replace any relative part of thebaseUri
.
It's the intended behavior. If you specify a relative path that begins with a slash, it assumes that the relative path is the entire relative path, so it discards any relative path already included in baseUri
.
I had to dig into the documentation for the constructor you're calling.
public Uri (Uri baseUri, string relativeUri);
Additionally, if the
relativeUri
begins with a slash, then it will replace any relative part of thebaseUri
.
It's the intended behavior. If you specify a relative path that begins with a slash, it assumes that the relative path is the entire relative path, so it discards any relative path already included in baseUri
.
edited Nov 13 '18 at 17:56
answered Nov 13 '18 at 17:12
Scott HannenScott Hannen
12.7k1425
12.7k1425
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53286212%2fwhy-does-the-uri-constructor-remove-part-of-path-from-the-baseuri-argument%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Because the
/
in/controller
indicates "from root" where root ishttp://localhost:7777
.– Sani Singh Huttunen
Nov 13 '18 at 17:09
You need to do
new Uri(baseUri, "./controller")
to state that your path is relative from the current path (denoted by the dot). This will returnhttp://localhost:7777/BasePath/controller
.– ckuri
Nov 13 '18 at 18:21
Or keep your
baseUri
and yourrelativeUri
separate.Uri baseUri = new Uri("http://localhost:7777"); Uri uri = new Uri(baseUri, "/BasePath/controller");
That way there's nothing to accidentally overwrite.– Scott Hannen
Nov 13 '18 at 19:01