Getting MVC Default Route To Go To ~/default.asp
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.
Answer
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...
Related Questions
- → ASP.NET Mvc 5 return View with seo friendly url
- → MVC- How to get parameter value from get request which has parameter names including dot characters
- → 301 Redirection Layer in Microsoft asp.net MVC using phil haacked code doesn't work for me
- → Invoke ASP.Net Core MVC controller action with parameter doesn't work
- → Use the routing engine for form submissions in ASP.NET MVC Preview 4
- → ASP.NET MVC Beta - Grouping Controllers and Views possible?
- → Getting MVC default route to go to ~/default.asp
- → How do I get rid of Home in ASP.Net MVC?
- → ASP.NET MVC routes
- → MVC Beta 1 Routing - what number of routes will start to cause performance issues?