Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Diagnosing 404 errors on IIS 7 and ASP.NET MVC

I have an mvc app developed and tested with Cassini. Deployed to my site on GoDaddy, and the default page comes up fine. Click to log in, and I get a 404.

I'm running under IIS 7 there, so this is unexpected. My routes are pretty plain:

        routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

        routes.MapRoute(
            "Default",                                              
            "{controller}/{action}/{id}",                           
            new { controller = "Public", action = "Index", id = "" } 
        );
        routes.MapRoute(
            "Report1",
            "Report/{action}/{start}/{end}",
            new { controller = "Report", action = "Index" }
        );
        routes.MapRoute(
            "Report2",
            "Report/{action}/{start}/{end}/{idList}",
            new { controller = "Report", action = "Index" }
        );

Any idea what might be going on or how I can troubleshoot this?

like image 323
Stuart Avatar asked Apr 01 '09 12:04

Stuart


People also ask

Why am I getting a 404 error on ASP NET MVC?

The URL does not match any route in the routing table. A suitable controller is not found. A suitable controller action is not found. The status code of the server's response is 404.

What is the error message for 404 in asp net?

Best web development and SEO practices dictate that any webpage which does not exist, return an HTTP response code of 404, or Not Found. Basically, this response code means that the URL that you're requesting does not exist.

What is IIS in MVC?

IIS seems to be an application that listens for incoming connections, parses the data sent there as HTTP requests, and maps request urls to directories based on a site an application and a virtual directory , and then does something based on the file present (or not present) on that location.


2 Answers

Are you running in IIS7 integrated mode?

Classic mode of IIS7 does not automatically map extensionless URLs to ASP.NET (much like IIS6).

Also make sure your Web.config <system.webServer> tag is configured correctly.

like image 187
mmx Avatar answered Sep 21 '22 13:09

mmx


Don't use runAllManagedModulesForAllRequests. You want to let IIS handle resources such as images.

<system.webServer> <!-- Rather do NOT use this -->
  <modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>

Instead add the MVC routing module

<system.webServer>
  <modules>
    <remove name="UrlRoutingModule-4.0" />
    <add name="UrlRoutingModule-4.0" type="System.Web.Routing.UrlRoutingModule" preCondition="" />
  </modules>
</system.webServer>
like image 26
Chris Herring Avatar answered Sep 25 '22 13:09

Chris Herring