ASP.NET Core routing prefix

后端 未结 5 1083
余生分开走
余生分开走 2021-01-17 17:45

I\'m developing an ASP.NET Core application. My application hosted with NGinx on url http://somedomain.com/MyApplication.

I need all requests routed to

5条回答
  •  夕颜
    夕颜 (楼主)
    2021-01-17 17:57

    you can use the PathBase middleware just before Mvc like this :

    partial class Startup {
    
        public void Configure(
            IApplicationBuilder app,
            IHostingEnvironment env
        ) {
            app.UsePathBase(new PathString("/MyApplication"));
            app.UseMvc();
        }
    
    }
    

    with the PathBase middleware, no need to change any mvc code, it will automatically add to the request and response.

    please refer to https://docs.microsoft.com/en-us/dotnet/api/microsoft.aspnetcore.builder.usepathbaseextensions.usepathbase?view=aspnetcore-2.2

提交回复
热议问题