ASP.NET Core路由前缀 [英] ASP.NET Core routing prefix

查看:654
本文介绍了ASP.NET Core路由前缀的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发ASP.NET Core应用程序。我的应用程序使用NGinx托管在url http://somedomain.com/MyApplication

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

我需要路由所有请求前缀 / MyApplication

I need all requests routed to prefix /MyApplication.

我的控制器操作问题已将响应重定向到 somedomain.com ,而不是 somedomain.com/MyApplication

My problem with controllers actions responses redirects to somedomain.com, not to somedomain.com/MyApplication.

有什么方法可以配置使用前缀 / MyApplication 的路由?

Is there any way to configure routes to use prefix /MyApplication?

UPD:例如

        [HttpGet]
        [AllowAnonymous]
        public async Task<IActionResult> Login(string returnUrl = null)
        {
            // Clear the existing external cookie to ensure a clean login process
            await HttpContext.SignOutAsync(IdentityConstants.ExternalScheme);

            ViewData["ReturnUrl"] = returnUrl;
            return View();
        }

重定向到somedomain.com,但我需要somedomain.com/MyApplication

redirects to somedomain.com, but i need to somedomain.com/MyApplication

推荐答案

您可以在 PathBase 中间件> Mvc 像这样:

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

}

PathBase 中间件,无需更改任何mvc代码,它将自动添加到请求和响应中。

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

请参考 https://docs.microsoft.com/zh-CN/dotnet/api/microsoft.aspnetcore.builder.usepathbaseextensions.usepathbase?view=aspnetcore-2.2

这篇关于ASP.NET Core路由前缀的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆