For some reason my routing is ignoring any attempt to access my MVC pages and simply giving me 404s. I have a WebForms app set up like the following:
Virtual Directory: thing
So I usually access my site like so:
The original stucture of my ASP.NET WebForms app mirrors the file system so I have folders full of .aspx files and I need to be able to use them like that. For some reason when I try to access a page using the MVC routing such as:
I just get a 404 error. I have used ASP.NET MVC on it's own and I know that even if I didn't set up my folders properly, I wouldn't get a 404. I would get the reasons why the page couldn't be found and hints to where the files should be. Below is my routing info. Where am I going wrong?
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.IgnoreRoute("{resource}.aspx/{*pathInfo}");
routes.MapRoute(
"Default",
// Route name
"{controller}/{action}/{id}",
// URL with parameters
new { controller = "Home", action = "Index", id = "" }
// Parameter defaults
);
}
protected void Application_Start()
{
RegisterRoutes(RouteTable.Routes);
}
Best Answer
Can you tell me what OS you're running on and whether this site is running under VS.NET Web Dev server or IIS?
Routing in MVC directs a request to a Controller class and then a specific Action method. Do you have a class named HomeController with a method named Index?
Assuming you had a controller that looked this this...
... then the url you mentioned should work. However, ASP.NET MVC will expect to find any views associated with the Home controller in a folder named Views\Home or Views\Shared under your vdir. In this case, for the Index action, it will expect to find a view named Index.aspx (or .ascx). However, a missing view doesn't usually result in 404 - that's usually caused by the controller not being found, the action method not being found, or on IIS 6 the asp.net pipeline not being in the wildcard settings for the vdir.
update:
Are you sure your web.config has the MVC HttpHandler in place (so that MVC is in the ASP.NET pipeline). You should have something like this...
... in your
httpHandlers
section and this...... in your 'httpModules' section of web.config.
update 2:
Based upon your comments I suspect you've not got the ASP.NET MVC code in the pipeline. You should take your web.config and compare it with one from a freshly created MVC site and look for the missing config items. I've suggested a couple above, but there might be more.