19

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?

hlovdal
  • 26,565
  • 10
  • 94
  • 165
Stuart
  • 1,572
  • 4
  • 21
  • 39

4 Answers4

31

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.

Mehrdad Afshari
  • 414,610
  • 91
  • 852
  • 789
24

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>
David d C e Freitas
  • 7,481
  • 4
  • 58
  • 67
Chris Herring
  • 3,675
  • 3
  • 33
  • 50
  • This answer also worked and does appear to have a more efficient (and elegant) approach. – Ross Brasseaux Sep 13 '13 at 00:11
  • 2
    This method worked well for me in an ASP.NET Web API application. The app worked fined locally, but when deployed to any other environment, I just received a 404 for any Web API request. Added the routing module bits noted above and everything is fine. Similar issue here: http://stackoverflow.com/questions/15389855/asp-net-web-api-application-gives-404-when-deployed-at-iis-7. Thanks! – Adam Weber Oct 17 '13 at 13:52
  • I was pulling my hair out trying to get an MVC app to accept HTTP DELETE requests. This took care of it for me. Thanks! – Furynation Nov 17 '13 at 17:05
  • same problem, the method delete request don't work if i deploy to other environment: iis 8 ok but in other environment (iis 7) i get 404 – ios_dotnet_superuser Sep 07 '16 at 13:15
14

Tried everything, I had to set my web config like this, to make it work.

 <system.webServer>
    <validation validateIntegratedModeConfiguration="false"/>
    <modules runAllManagedModulesForAllRequests="true"/>
  </system.webServer>
Stasevich
  • 165
  • 1
  • 2
1

I had the same problem, I uploaded the controller, web.config and other classes but I forgot to upload the bin folder.

After I uploaded the bin folder, it worked!

Cedric Berlanger
  • 231
  • 1
  • 3
  • 10