Sme*_*egs 5 c# asp.net-mvc asp.net-core
我用于RedirectToAction
重定向到不同的视图,但是我在 IIS 的站点中使用应用程序,因此必须有一个前缀转到该路径。
当我这样做时,RedirectToAction
它只是重定向到根目录。
我需要它尊重当前路径并沿着这些路线重定向。
例如:
我上线了https://localhost:8085/app/custompath/controller1/action
我打电话给
return RedirectToAction("controller2", "action");
我被重定向到
https://localhost:8085/controller2/action
代替
https://localhost:8085/app/custompath/controller2/action
如果你的 中有这样的东西Starup.cs
:
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
routes.MapRoute(
name: "custom",
template: "app/custompath/{controller=Home}/{action=Index}");
});
Run Code Online (Sandbox Code Playgroud)
然后你可以这样做来重定向:
var url = Url.RouteUrl("custom", new { controller = "controller2", action = "action" });
return Redirect(url);
Run Code Online (Sandbox Code Playgroud)
顺便说一句,如果您需要,.NET Core 具有内置的URL 重写功能。
归档时间: |
|
查看次数: |
3954 次 |
最近记录: |