Kestrel no longer splits path and path base










1















I have created a sample service fabric application in .NET Core and tried to register URLs in Kestrel but getting below error.
Kestrel no longer splits path and path base. A path base specified in UseUrls() will no longer work. To specify a path base, use the IApplicationBuilder.UsePathBase() extension method.



The serverUrl will be: http://localhost:8597/School/LOCAL



Below is the code in stateless services



public Task<string> OpenAsync(CancellationToken cancellationToken)

var endpoint = FabricRuntime.GetActivationContext().GetEndpoint(this._endpointName);
string serverUrl = $"endpoint.Protocol://FabricRuntime.GetNodeContext().IPAddressOrFQDN:endpoint.Port";

// serverUrl = http://localhost:8597
serverUrl = serverUrl + "/School/LOCAL/";

webHost = new WebHostBuilder()
.UseKestrel()
.UseContentRoot(Directory.GetCurrentDirectory())
.UseStartup<Startup>()
.UseUrls(serverUrl)
.Build();

webHost.Start();

return Task.FromResult(serverUrl);



So I have modified my code as below and tried to register my Url with IApplicationBuilder.UsePathBase(). However, I have observed below behavior.



http://localhost:8597/School/LOCAL/api/getstudentnames - Not Working
http://localhost:8597/api/getstudentnames - Working



Code Changes using UsePathBase



CommunicationListener.CS



 public Task<string> OpenAsync(CancellationToken cancellationToken)

var endpoint = FabricRuntime.GetActivationContext().GetEndpoint(this._endpointName);
string serverUrl = $"endpoint.Protocol://FabricRuntime.GetNodeContext().IPAddressOrFQDN:endpoint.Port";
webHost = new WebHostBuilder()
.UseKestrel()
.UseContentRoot(Directory.GetCurrentDirectory())
.UseStartup<Startup>()
.UseUrls(serverUrl)
.Build();

webHost.Start();

return Task.FromResult(serverUrl);



Startup.cs



 public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)

const string PathBase = "/School/LOCAL/";
app.UsePathBase(PathBase);










share|improve this question


























    1















    I have created a sample service fabric application in .NET Core and tried to register URLs in Kestrel but getting below error.
    Kestrel no longer splits path and path base. A path base specified in UseUrls() will no longer work. To specify a path base, use the IApplicationBuilder.UsePathBase() extension method.



    The serverUrl will be: http://localhost:8597/School/LOCAL



    Below is the code in stateless services



    public Task<string> OpenAsync(CancellationToken cancellationToken)

    var endpoint = FabricRuntime.GetActivationContext().GetEndpoint(this._endpointName);
    string serverUrl = $"endpoint.Protocol://FabricRuntime.GetNodeContext().IPAddressOrFQDN:endpoint.Port";

    // serverUrl = http://localhost:8597
    serverUrl = serverUrl + "/School/LOCAL/";

    webHost = new WebHostBuilder()
    .UseKestrel()
    .UseContentRoot(Directory.GetCurrentDirectory())
    .UseStartup<Startup>()
    .UseUrls(serverUrl)
    .Build();

    webHost.Start();

    return Task.FromResult(serverUrl);



    So I have modified my code as below and tried to register my Url with IApplicationBuilder.UsePathBase(). However, I have observed below behavior.



    http://localhost:8597/School/LOCAL/api/getstudentnames - Not Working
    http://localhost:8597/api/getstudentnames - Working



    Code Changes using UsePathBase



    CommunicationListener.CS



     public Task<string> OpenAsync(CancellationToken cancellationToken)

    var endpoint = FabricRuntime.GetActivationContext().GetEndpoint(this._endpointName);
    string serverUrl = $"endpoint.Protocol://FabricRuntime.GetNodeContext().IPAddressOrFQDN:endpoint.Port";
    webHost = new WebHostBuilder()
    .UseKestrel()
    .UseContentRoot(Directory.GetCurrentDirectory())
    .UseStartup<Startup>()
    .UseUrls(serverUrl)
    .Build();

    webHost.Start();

    return Task.FromResult(serverUrl);



    Startup.cs



     public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)

    const string PathBase = "/School/LOCAL/";
    app.UsePathBase(PathBase);










    share|improve this question
























      1












      1








      1








      I have created a sample service fabric application in .NET Core and tried to register URLs in Kestrel but getting below error.
      Kestrel no longer splits path and path base. A path base specified in UseUrls() will no longer work. To specify a path base, use the IApplicationBuilder.UsePathBase() extension method.



      The serverUrl will be: http://localhost:8597/School/LOCAL



      Below is the code in stateless services



      public Task<string> OpenAsync(CancellationToken cancellationToken)

      var endpoint = FabricRuntime.GetActivationContext().GetEndpoint(this._endpointName);
      string serverUrl = $"endpoint.Protocol://FabricRuntime.GetNodeContext().IPAddressOrFQDN:endpoint.Port";

      // serverUrl = http://localhost:8597
      serverUrl = serverUrl + "/School/LOCAL/";

      webHost = new WebHostBuilder()
      .UseKestrel()
      .UseContentRoot(Directory.GetCurrentDirectory())
      .UseStartup<Startup>()
      .UseUrls(serverUrl)
      .Build();

      webHost.Start();

      return Task.FromResult(serverUrl);



      So I have modified my code as below and tried to register my Url with IApplicationBuilder.UsePathBase(). However, I have observed below behavior.



      http://localhost:8597/School/LOCAL/api/getstudentnames - Not Working
      http://localhost:8597/api/getstudentnames - Working



      Code Changes using UsePathBase



      CommunicationListener.CS



       public Task<string> OpenAsync(CancellationToken cancellationToken)

      var endpoint = FabricRuntime.GetActivationContext().GetEndpoint(this._endpointName);
      string serverUrl = $"endpoint.Protocol://FabricRuntime.GetNodeContext().IPAddressOrFQDN:endpoint.Port";
      webHost = new WebHostBuilder()
      .UseKestrel()
      .UseContentRoot(Directory.GetCurrentDirectory())
      .UseStartup<Startup>()
      .UseUrls(serverUrl)
      .Build();

      webHost.Start();

      return Task.FromResult(serverUrl);



      Startup.cs



       public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)

      const string PathBase = "/School/LOCAL/";
      app.UsePathBase(PathBase);










      share|improve this question














      I have created a sample service fabric application in .NET Core and tried to register URLs in Kestrel but getting below error.
      Kestrel no longer splits path and path base. A path base specified in UseUrls() will no longer work. To specify a path base, use the IApplicationBuilder.UsePathBase() extension method.



      The serverUrl will be: http://localhost:8597/School/LOCAL



      Below is the code in stateless services



      public Task<string> OpenAsync(CancellationToken cancellationToken)

      var endpoint = FabricRuntime.GetActivationContext().GetEndpoint(this._endpointName);
      string serverUrl = $"endpoint.Protocol://FabricRuntime.GetNodeContext().IPAddressOrFQDN:endpoint.Port";

      // serverUrl = http://localhost:8597
      serverUrl = serverUrl + "/School/LOCAL/";

      webHost = new WebHostBuilder()
      .UseKestrel()
      .UseContentRoot(Directory.GetCurrentDirectory())
      .UseStartup<Startup>()
      .UseUrls(serverUrl)
      .Build();

      webHost.Start();

      return Task.FromResult(serverUrl);



      So I have modified my code as below and tried to register my Url with IApplicationBuilder.UsePathBase(). However, I have observed below behavior.



      http://localhost:8597/School/LOCAL/api/getstudentnames - Not Working
      http://localhost:8597/api/getstudentnames - Working



      Code Changes using UsePathBase



      CommunicationListener.CS



       public Task<string> OpenAsync(CancellationToken cancellationToken)

      var endpoint = FabricRuntime.GetActivationContext().GetEndpoint(this._endpointName);
      string serverUrl = $"endpoint.Protocol://FabricRuntime.GetNodeContext().IPAddressOrFQDN:endpoint.Port";
      webHost = new WebHostBuilder()
      .UseKestrel()
      .UseContentRoot(Directory.GetCurrentDirectory())
      .UseStartup<Startup>()
      .UseUrls(serverUrl)
      .Build();

      webHost.Start();

      return Task.FromResult(serverUrl);



      Startup.cs



       public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)

      const string PathBase = "/School/LOCAL/";
      app.UsePathBase(PathBase);







      azure-devops azure-service-fabric service-fabric-stateful kestrel service-fabric-stateless






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 14 '18 at 10:13









      Balanjaneyulu KBalanjaneyulu K

      4641719




      4641719






















          1 Answer
          1






          active

          oldest

          votes


















          0














          I think this is working as expected.



          AFAIK, the UsePathBase() feature has been added to remove the rootPath from the actual path received in the request for scenarios where the client request something via a reverse proxy that route requests based on VirtualPaths and the original URL must be rewritten in the service to understand it.



          As Example:



          • An API accept requests on http://<anyip>/users/123

          • The API is exposed behind a proxy setup as a virtual directory like http://domain/api

          • A client call http://domain/api/users/123

          • The proxy receive the call as http://domain/api/users/123 and forward as is to the API that http://domain/users/123

          • The API does not recognize the Url and return 404,

          In this scenario, if you configure with UserPathBase("api") it will strip the api value from the URL to map to the route you had before.



          An example is the one reported on this issue, as below:



           public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)

          app.UsePathBase("/basepath");

          app.Map("/ping", map => map.Run(async
          ctx => await ctx.Response.WriteAsync("pong")));

          app.UseMvc();



          This will work for both urls below:



          • /basepath/ping

          • /ping

          Because the basepath in the first will be removed and the API will always see second option.



          This explain in more details, and this shows a issue similar to yours.



          Another issue, is when the API return internal URLs, so for example, if had to generate the link to a user, without knowing it is behind a proxy, it would return http://<anyip>/users/123 where the right url should be http://<anyip>/api/users/123.



          In summary, the API has to to the work that should be handled by the proxy, but some proxies is just a bridge and does not handle these cases.






          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%2f53297711%2fkestrel-no-longer-splits-path-and-path-base%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 think this is working as expected.



            AFAIK, the UsePathBase() feature has been added to remove the rootPath from the actual path received in the request for scenarios where the client request something via a reverse proxy that route requests based on VirtualPaths and the original URL must be rewritten in the service to understand it.



            As Example:



            • An API accept requests on http://<anyip>/users/123

            • The API is exposed behind a proxy setup as a virtual directory like http://domain/api

            • A client call http://domain/api/users/123

            • The proxy receive the call as http://domain/api/users/123 and forward as is to the API that http://domain/users/123

            • The API does not recognize the Url and return 404,

            In this scenario, if you configure with UserPathBase("api") it will strip the api value from the URL to map to the route you had before.



            An example is the one reported on this issue, as below:



             public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)

            app.UsePathBase("/basepath");

            app.Map("/ping", map => map.Run(async
            ctx => await ctx.Response.WriteAsync("pong")));

            app.UseMvc();



            This will work for both urls below:



            • /basepath/ping

            • /ping

            Because the basepath in the first will be removed and the API will always see second option.



            This explain in more details, and this shows a issue similar to yours.



            Another issue, is when the API return internal URLs, so for example, if had to generate the link to a user, without knowing it is behind a proxy, it would return http://<anyip>/users/123 where the right url should be http://<anyip>/api/users/123.



            In summary, the API has to to the work that should be handled by the proxy, but some proxies is just a bridge and does not handle these cases.






            share|improve this answer





























              0














              I think this is working as expected.



              AFAIK, the UsePathBase() feature has been added to remove the rootPath from the actual path received in the request for scenarios where the client request something via a reverse proxy that route requests based on VirtualPaths and the original URL must be rewritten in the service to understand it.



              As Example:



              • An API accept requests on http://<anyip>/users/123

              • The API is exposed behind a proxy setup as a virtual directory like http://domain/api

              • A client call http://domain/api/users/123

              • The proxy receive the call as http://domain/api/users/123 and forward as is to the API that http://domain/users/123

              • The API does not recognize the Url and return 404,

              In this scenario, if you configure with UserPathBase("api") it will strip the api value from the URL to map to the route you had before.



              An example is the one reported on this issue, as below:



               public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)

              app.UsePathBase("/basepath");

              app.Map("/ping", map => map.Run(async
              ctx => await ctx.Response.WriteAsync("pong")));

              app.UseMvc();



              This will work for both urls below:



              • /basepath/ping

              • /ping

              Because the basepath in the first will be removed and the API will always see second option.



              This explain in more details, and this shows a issue similar to yours.



              Another issue, is when the API return internal URLs, so for example, if had to generate the link to a user, without knowing it is behind a proxy, it would return http://<anyip>/users/123 where the right url should be http://<anyip>/api/users/123.



              In summary, the API has to to the work that should be handled by the proxy, but some proxies is just a bridge and does not handle these cases.






              share|improve this answer



























                0












                0








                0







                I think this is working as expected.



                AFAIK, the UsePathBase() feature has been added to remove the rootPath from the actual path received in the request for scenarios where the client request something via a reverse proxy that route requests based on VirtualPaths and the original URL must be rewritten in the service to understand it.



                As Example:



                • An API accept requests on http://<anyip>/users/123

                • The API is exposed behind a proxy setup as a virtual directory like http://domain/api

                • A client call http://domain/api/users/123

                • The proxy receive the call as http://domain/api/users/123 and forward as is to the API that http://domain/users/123

                • The API does not recognize the Url and return 404,

                In this scenario, if you configure with UserPathBase("api") it will strip the api value from the URL to map to the route you had before.



                An example is the one reported on this issue, as below:



                 public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)

                app.UsePathBase("/basepath");

                app.Map("/ping", map => map.Run(async
                ctx => await ctx.Response.WriteAsync("pong")));

                app.UseMvc();



                This will work for both urls below:



                • /basepath/ping

                • /ping

                Because the basepath in the first will be removed and the API will always see second option.



                This explain in more details, and this shows a issue similar to yours.



                Another issue, is when the API return internal URLs, so for example, if had to generate the link to a user, without knowing it is behind a proxy, it would return http://<anyip>/users/123 where the right url should be http://<anyip>/api/users/123.



                In summary, the API has to to the work that should be handled by the proxy, but some proxies is just a bridge and does not handle these cases.






                share|improve this answer















                I think this is working as expected.



                AFAIK, the UsePathBase() feature has been added to remove the rootPath from the actual path received in the request for scenarios where the client request something via a reverse proxy that route requests based on VirtualPaths and the original URL must be rewritten in the service to understand it.



                As Example:



                • An API accept requests on http://<anyip>/users/123

                • The API is exposed behind a proxy setup as a virtual directory like http://domain/api

                • A client call http://domain/api/users/123

                • The proxy receive the call as http://domain/api/users/123 and forward as is to the API that http://domain/users/123

                • The API does not recognize the Url and return 404,

                In this scenario, if you configure with UserPathBase("api") it will strip the api value from the URL to map to the route you had before.



                An example is the one reported on this issue, as below:



                 public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)

                app.UsePathBase("/basepath");

                app.Map("/ping", map => map.Run(async
                ctx => await ctx.Response.WriteAsync("pong")));

                app.UseMvc();



                This will work for both urls below:



                • /basepath/ping

                • /ping

                Because the basepath in the first will be removed and the API will always see second option.



                This explain in more details, and this shows a issue similar to yours.



                Another issue, is when the API return internal URLs, so for example, if had to generate the link to a user, without knowing it is behind a proxy, it would return http://<anyip>/users/123 where the right url should be http://<anyip>/api/users/123.



                In summary, the API has to to the work that should be handled by the proxy, but some proxies is just a bridge and does not handle these cases.







                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited Nov 15 '18 at 11:18

























                answered Nov 15 '18 at 11:12









                Diego MendesDiego Mendes

                4,69111827




                4,69111827





























                    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%2f53297711%2fkestrel-no-longer-splits-path-and-path-base%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







                    這個網誌中的熱門文章

                    How to read a connectionString WITH PROVIDER in .NET Core?

                    In R, how to develop a multiplot heatmap.2 figure showing key labels successfully

                    Museum of Modern and Contemporary Art of Trento and Rovereto