views:

344

answers:

1

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);
        }
+1  A: 

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

public class HomeController : Controller
{
    public ActionResult Index()
    {
        return View();
    }
}

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

<add verb="*" path="*.mvc" validate="false" type="System.Web.Mvc.MvcHttpHandler, System.Web.Mvc, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>

... in your httpHandlers section and this...

<add name="UrlRoutingModule" type="System.Web.Routing.UrlRoutingModule, System.Web.Routing, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>

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

Martin Peck
Windows 7 x64 - II7.5 - Site is running under IIS.I have the conventions in place. A controller called HomeController with an Index() method. I also have a View in Views/Home/ called Index.
Brian David Berman
Even if I didn't have the controllers and views in place, I wouldn't get a 404, I would get reasons why the route failed. This leads me to believe the routing is messed up.
Brian David Berman
Do you get any breakpoints being hit? Exceptions in the event viewer?
Martin Peck
You will get a 404 if the controller isn't found or the action method isn't found - that's the default behaviour in ASP.NET MVC. ASP.NET doesn't look for physical files until way after the point a 404 might be returned. For some actions a physical .aspx file might not be needed (JSON results for example)
Martin Peck
Breakpoints are being hit within the global.asax.cs and nothing in the event viewer. I am just getting the IIS 404.
Brian David Berman
Did this application start of as a new MVC app, or is it an evolved ASP.NET "classic" app?
Martin Peck
The application started as an ASP.NET WebForms app and ASP.NET MVC is being mixed in.
Brian David Berman
I was using Classic .NET AppPool. I think this is related to my problem but still not 100% sure.
Brian David Berman
This is marked as an answer - but its not clear what the answer is! I am having the same problem!
Sergio