C# 使用PathBase时重定向
我定义了类似PathBase的 新路径字符串/测试_环境/ 那我在https://localhost:5001/test_environment/Login 登录后,它会重定向到/MyController/ 一切正常-控制器及其方法可以正常访问并提供数据,但我在浏览器中的url是: https://localhost:5001/MyController/ 它工作正常,但是/test_environment/go在哪里 MyController中的MyMethod具有 [Route/]attribute对于app.UsePathBase,它添加了一个中间件,用于从请求路径提取指定的路径库,并将其后置到请求路径库 对于[Route/],它将生成请求https://localhost:5001/ 如果您使用RedirectToAction 你有https://localhost:5001/MyController/,我假设您使用重定向来重定向url 在登录中尝试下面的代码C# 使用PathBase时重定向,c#,asp.net-core,asp.net-core-mvc,C#,Asp.net Core,Asp.net Core Mvc,我定义了类似PathBase的 新路径字符串/测试_环境/ 那我在https://localhost:5001/test_environment/Login 登录后,它会重定向到/MyController/ 一切正常-控制器及其方法可以正常访问并提供数据,但我在浏览器中的url是: https://localhost:5001/MyController/ 它工作正常,但是/test_environment/go在哪里 MyController中的MyMethod具有 [Route/]attrib
多一点上下文代码会有所帮助。您在何时设置哪个PatBase?@bommelding ASP.NET Core MVC->启动时/使用app.UsePathBasenew PathString/test_environment/进行配置;
public IActionResult Login()
{
if (Request.Path.StartsWithSegments("/test_environment"))
{
return Redirect("/");
}
else
{
return Redirect("/test_environment/");
}
}