Why does the URI constructor remove part of path from the baseUri argument?












0















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?










share|improve this question

























  • 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











  • 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
















0















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?










share|improve this question

























  • 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











  • 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














0












0








0








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?










share|improve this question
















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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 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











  • 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



















  • 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











  • 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

















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












1 Answer
1






active

oldest

votes


















0














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 the baseUri.




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.






share|improve this answer

























    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
    });


    }
    });














    draft saved

    draft discarded


















    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









    0














    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 the baseUri.




    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.






    share|improve this answer






























      0














      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 the baseUri.




      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.






      share|improve this answer




























        0












        0








        0







        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 the baseUri.




        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.






        share|improve this answer















        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 the baseUri.




        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.







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Nov 13 '18 at 17:56

























        answered Nov 13 '18 at 17:12









        Scott HannenScott Hannen

        12.7k1425




        12.7k1425






























            draft saved

            draft discarded




















































            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.




            draft saved


            draft discarded














            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





















































            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







            Popular posts from this blog

            Florida Star v. B. J. F.

            Error while running script in elastic search , gateway timeout

            Adding quotations to stringified JSON object values