Getting MVC default route to go to ~/default.asp

冷暖自知 提交于 2019-12-13 15:54:47

问题


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.


回答1:


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:

routes.IgnoreRoute("default.asp/{*pathInfo}"); // If you don't pass arguments just use default.asp
routes.IgnoreRoute("");

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...



来源:https://stackoverflow.com/questions/3014889/getting-mvc-default-route-to-go-to-default-asp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!