获取 MVC 默认路由到 ~/default.asp
我正在向现有站点添加一些 MVC 功能(FWIW,其中大部分位于经典 ASP 中)。因此,我需要保留默认路由到 ~/default.asp(至少 - 最好是 IIS 中指定的默认文档)。
有没有办法在 RegisterRoutes 中编写路由,以便请求站点的根目录(例如 http://localhost 、 http://localhost/ 或 http://localhost/default.asp) 会直接获取默认页面,而不是尝试查找控制器/操作?或者我是否需要编写自己的 HttpModule 来过滤它并阻止它到达 MvcHandler (如 此博客)?
顺便说一句,我已经用 google 搜索过这个,但大多数点击都是针对 MVC 版本 1 或更早版本的,并且默认路由似乎在版本 2 中发生了变化(即,不再有 default.aspx 重定向到 ~/Home),所以它们不直接适用。即便如此,那里的人也没有解决这个问题。
I am adding some MVC features to an existing site (FWIW, most of which is in classic ASP). As a result, I need to keep the default routing going to ~/default.asp (at a minimum - preferably the default document specified in IIS).
Is there a way to write the route in RegisterRoutes so that a request for the root of the site (e.g., http://localhost, http://localhost/, or http://localhost/default.asp) will directly get the default page, and not attempt to find a controller/action? Or do I need to write my own HttpModule that will filter it and keep it from getting to the MvcHandler (as in this blog)?
BTW, I have googled this, but most of the hits are for MVC version 1 or older, and default routing appears to have changed in version 2 (i.e, there is no more default.aspx that redirects to ~/Home), so they are not directly applicable. Even so, the ones that were there didn't address this problem.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Maarten Balliauw 写了一篇关于混合 ASP 的好文章.NET Webforms 和 ASP.NET MVC。您从本文中需要的是告诉 MVC 不要路由某些路由的部分:
在您的情况下,这将是:
在这些忽略之后,提供常规 MVC 路由。这样,MVC 将忽略这些路由并让 Webforms 处理它们。如果
/
将指向 Webforms 中的/default.asp
,那么这应该可以工作。不过,我还没有测试过这个...Maarten Balliauw has written a nice artice about mixing ASP.NET Webforms and ASP.NET MVC. The thing you need from the article is the part where you tell MVC not to route certain routes:
In your case this would be:
After these ignores, provide your regular MVC routes. This way MVC will ignore these routes and will let Webforms handle them. Provided that
/
will point to/default.asp
in Webforms, this should work. However, I haven't tested this...