ASP.NET MVC:如何“理解”ASP.NET MVC遗留 URL 但不写它们?
请原谅这个令人困惑的标题;)
我们构建了一个 ASP.NET MVC 应用程序来取代我们的“旧”ASP.NET Webforms 怪物。我们仍然希望支持那里使用的一些旧 URL,因为这些 URL 可能仍然存在于电子邮件等其他地方。
例如:我们的旧系统使用的URL为~/Password.aspx,新MVC系统中的URL为~/Home/Password。
为了支持这些旧的 URL,我们只是将它们添加到路由表中,就像
routes.MapRoute(
"Password",
"Password.aspx",
new {
controller = "Home",
action = "Password",
id = ""
}
);
这样效果很好,但是每当我们在代码中使用 Url.Action("Password", "Home") 时,它都会生成旧的 URL ("~/Password .aspx”而不是“~/Home/Password”)。由于我们希望慢慢淘汰旧 URL,因此如果 MVC 路由仍然“理解”旧 URL 但只使用/写入新 URL,那就太好了。
有办法实现这一点吗?
Please excuse the confusing title ;)
We've built an ASP.NET MVC application to replace our "old" ASP.NET webforms monster. We still want to support some of the old URLs used there, because these may still float around in E-Mails etc. somewhere out there.
For example: Our old system used the URL ~/Password.aspx, the URL in the new MVC system is ~/Home/Password.
To support these old URLs, we just added them to the route table, like
routes.MapRoute(
"Password",
"Password.aspx",
new {
controller = "Home",
action = "Password",
id = ""
}
);
This works great, but whenever we use Url.Action("Password", "Home") in our code, it generates the old URL ("~/Password.aspx" instead of "~/Home/Password"). Since we want to slowly phase out the old URLs, it would be nice if the MVC routes still "understood" the old URLs but only use/write the new ones.
Is there a way to achieve this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
将新路由放在路由表中旧路由的上方。路由越高,其优先级就越高:
Put the new route above the old route on the routing table. The higher up the route is, the more precedence it will have: