I have an existing ASP.Net Application, into which I am attempting to introduce MVC2.
Ho开发者_高级运维pefully I can remember the steps, but what I did was the following:
- Created a dummy MVC2 project.
- Compared and merged .csproj, resulting in the Add Item commands showing MVC2 items.
- Compared and merged the web.config
- Compared and merged the global.asax.cs
- Added Models, Views and Controllers directories
- Added HostController with Index action and Index.aspx (no logic)
- Amended route to make /Host/Index the default
So now, when I access the application via the root address http://localhost/MyApp it all works.
But, when I access http://localhost/MyApp/Host/Index I get a 404 error. I get the same result for any of the Controller/Actions I created. The only way I can get them to appear is to use the defaults in the routing configuration. I installed Phill Haack's route debugger and it's doing nothing. Obviously there's some problem with my routing, but I can't figure it out.
Any ideas what I've missed?
Bah... turns out that this is to do with IIS 5.1 and MVC routing.
I resolved it by using the following Routes in my application (note the .aspx extensions).
routes.MapRoute("Root", "", new { controller = "Host", action = "Index" });
routes.MapRoute("Default", "{controller}/{action}.aspx", new { controller = "Host", action = "Index" });
Means I can't have clean routes, but at least it works.
精彩评论