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

时间:2009-04-01 12:16:27

标签: asp.net asp.net-mvc iis 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" }
        );

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

4 个答案:

答案 0 :(得分:29)

您是在IIS7中运行集成模式吗?

IIS7的经典模式会自动将无扩展名的URL映射到ASP.NET(非常类似于IIS6)。

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

答案 1 :(得分:23)

Don't use runAllManagedModulesForAllRequests。您希望让IIS处理图像等资源。

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

而是添加MVC路由模块

<system.webServer>
  <modules>
    <remove name="UrlRoutingModule-4.0" />
    <add name="UrlRoutingModule-4.0" type="System.Web.Routing.UrlRoutingModule" preCondition="" />
  </modules>
</system.webServer>

答案 2 :(得分:14)

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

 <system.webServer>
    <validation validateIntegratedModeConfiguration="false"/>
    <modules runAllManagedModulesForAllRequests="true"/>
  </system.webServer>

答案 3 :(得分:1)

我有同样的问题,我上传了控制器,web.config和其他类,但我忘了上传bin文件夹。

上传bin文件夹后,它有效!