MVC或WebAPI发布后报错404问题的总结

在MVC项目或者webAPI项目发布之后有时会发生404错误。针对这种错误的解决办法:


解决办法1(不推荐):
在webconfig中 <system.webServer> 节点下 添加 <Modules runAllManagedModulesForAllRequests="true" >的节点

<system.webServer>
  <modules runAllManagedModulesForAllRequests="true"> 
  </modules>
</system.webServer>

1、这些问题的形式是使所有注册的HTTP模块在每个请求上运行,而不仅仅是托管请求。比如图片、CSS等。

2、可能导出全局错误,并且浪费服务器资源

解决办法2(比较好):

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

解决办法3(更好):

<system.webServer>
   <handlers>
     <add  name="htmlHandler" verb="GET,HEAD" path="*.html" type="System.Web.StaticFileHandler"/>
   </handlers>
 </system.webServer>

  

原文地址:https://www.cnblogs.com/zhaochengshen/p/8397548.html