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>

  

  

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM