mvc路由配置.html结尾的伪静态

    mvc 标准的写法 通常是(http://localhost:8149/Home/Index) 路由配置如下:

    有时候需求 如 http://localhost:8149/Home/Index 改为http://localhost:8149/index.html 让其看起来更加像一个静态网站

   

       //配置首页 伪静态 路由
            routes.MapRoute("pc_index", "index.html", new { controller = "Home", action = "Index" });

 然而  

解决方式一(不建议)修改 Web.config 文件  

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

这种方式强烈不建议:
1、这些问题的形式是使所有注册的HTTP模块在每个请求上运行,而不仅仅是托管请求(例如.html)。 这意味着模块将永远运行.jpg .gif .css .aspx等
2、浪费资源
3、并具有可能导致错误的全局效应

更好的解决方案(方式二)

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

更好的解决方案(方式三)

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

  

  

原文地址:https://www.cnblogs.com/LoveTX/p/7701689.html