ASP.NET MVC 路由:如何将所有操作重定向到基本 URL?
无论如何,是否可以使给定控制器中的所有操作重定向到服务器根目录?
例如,如果我有一个带有控制器 Home 和操作 terms 的 URL,我希望该 URL 变为 /terms
如果我有另一个带有控制器 Home< 的 URL /strong> 和操作 隐私,那么 URL 应变为 /privacy。
我可以通过硬编码 2 条路线来做到这一点,但是有没有办法自动做到这一点?
routes.MapRoute(
"Term",
"terms",
new { controller = "Home", action = "terms" }
);
routes.MapRoute(
"Privacy",
"privacy",
new { controller = "Home", action = "privacy" }
);
Is there anyway to make all actions in a given controller to redirect to the server root?
For example, if I have a URL with controller Home and action terms I want that to the URL to become /terms
If I have another URL with controller Home and action privacy, then the URL should become /privacy.
I am able to do this by hard-coding 2 routes, but is there a way to automatically do this?
routes.MapRoute(
"Term",
"terms",
new { controller = "Home", action = "terms" }
);
routes.MapRoute(
"Privacy",
"privacy",
new { controller = "Home", action = "privacy" }
);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
对两条路由进行硬编码是自动方式。
Hard coding the two routes is the automatic way.