诊断IIS 7和ASP.NET MVC上的404错误

Stu*_*art 19 asp.net iis asp.net-mvc iis-7 httphandler

我有一个用Cassini开发和测试的mvc应用程序.在GoDaddy上部署到我的网站,默认页面就可以了.点击登录,我得到404.

我在IIS 7下运行,所以这是出乎意料的.我的路线很简单:

        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" }
        );
Run Code Online (Sandbox Code Playgroud)

知道可能会发生什么或我如何解决这个问题?

Meh*_*ari 29

你在IIS7 集成模式下运行吗?

IIS7的经典模式不会自动将无扩展名的URL映射到ASP.NET(很像IIS6).

还要确保您的Web.config <system.webServer>标记配置正确.

  • <system.webServer> <modules runAllManagedModulesForAllRequests ="true"/> </system.webServer> (3认同)

Chr*_*ing 23

不要使用runAllManagedModulesForAllRequests.您希望让IIS处理图像等资源.

<system.webServer> <!-- Rather do NOT use this -->
  <modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
Run Code Online (Sandbox Code Playgroud)

而是添加MVC路由模块

<system.webServer>
  <modules>
    <remove name="UrlRoutingModule-4.0" />
    <add name="UrlRoutingModule-4.0" type="System.Web.Routing.UrlRoutingModule" preCondition="" />
  </modules>
</system.webServer>
Run Code Online (Sandbox Code Playgroud)

  • 在ASP.NET Web API应用程序中,此方法适用于我.该应用程序在本地工作,但当部署到任何其他环境时,我刚收到404任何Web API请求.添加了上面提到的路由模块位,一切都很好.类似的问题在这里:http://stackoverflow.com/questions/15389855/asp-net-web-api-application-gives-404-when-deployed-at-iis-7.谢谢! (2认同)

小智 14

尝试了一切,我必须像这样设置我的网络配置,以使其工作.

 <system.webServer>
    <validation validateIntegratedModeConfiguration="false"/>
    <modules runAllManagedModulesForAllRequests="true"/>
  </system.webServer>
Run Code Online (Sandbox Code Playgroud)

  • 哇这真的有效!但为什么我会觉得它会回来困扰我? (2认同)