【发布时间】:2019-10-21 17:33:06
【问题描述】:
我正在开发一个 ASP.NET Core 应用程序。我的应用程序在 url http://somedomain.com/MyApplication 上使用 NGinx 托管。
我需要将所有请求路由到前缀 /MyApplication。
控制器操作响应重定向到somedomain.com,而不是somedomain.com/MyApplication。
有没有办法配置路由使用前缀/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
【问题讨论】:
-
如何生成应该包含“/MyApplication”但不包含的 URL?
-
我不会把这个逻辑放在 ASPCore 应用程序中。而是让 nginx 去掉前缀
/MyApplication并将重要的内容传递给应用程序。 -
我会看看我是否能找到解决这个问题的 Nginx 方法。传入请求到 /MyApplication 的映射由 Nginx 完成,修改响应中的任何 URL 也应该是 Nginx 的责任。如果你让你的 C# 程序知道 Nginx 正在修改传入的请求,那么你需要让 Nginx 和你的应用程序保持同步,这就是在问问题。
标签: c# .net asp.net-core routing