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

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


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

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

一、这些问题的形式是使全部注册的HTTP模块在每一个请求上运行,而不单单是托管请求。好比图片、CSS等。服务器

二、可能导出全局错误,而且浪费服务器资源spa

 

解决办法2(比较好):
htm

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

 

解决办法3(更好):blog

<system.webServer>
   <handlers>
     <add  name="htmlHandler" verb="GET,HEAD" path="*.html" type="System.Web.StaticFileHandler"/>
   </handlers>
 </system.webServer>
相关文章
相关标签/搜索