mvc 后缀 路由 伪静态
当对接第三方站长爬虫时,要求以.html结尾,项目是mvc4实现的,修改路由
routes.MapRoute( name: "Default", url: "{controller}/{action}.html", defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional } );
访问报错404 ,
解决方案1:
于是网上找解决方法,不少页面推荐
<modules runAllManagedModulesForAllRequests="true" />
解决方案2:
但是有人反对,http://www.britishdeveloper.co.uk/2010/06/dont-use-modules-runallmanagedmodulesfo.html
大意是说会造成资源的浪费,还会导致潜在的威胁(本人英文不好,仅能理解大概,详细请看原文)在原文中给出了解决方案:
<modules> <remove name="UrlRoutingModule-4.0" /> <add name="UrlRoutingModule-4.0" type="System.Web.Routing.UrlRoutingModule" preCondition="" /> <!-- any other modules you want to run in MVC e.g. FormsAuthentication, Roles etc. --></modules>经测试可行,
解决方案3:
http://www.cnblogs.com/TeyGao/archive/2012/06/01/2530743.html
这里提供了
<system.webServer>
<modules runAllManagedModulesForAllRequests="false" />
<handlers>
<add name="HtmlFileHandler" path="*.html" verb="GET" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0"/>
</handlers>
</system.webServer>
对需要静态化的Action上添加属性标签
[StaticFileWriteFilter] public ActionResult Index(int ArticleId,int pageIndex)
当扩展不同的后缀时, 要 添加对应后缀 likepath="*.html"
代做毕业设计和论文 私活, 需要.net,asp.net ,mvc ef cs 客户端,bs 网站项目开发的请私信我,

浙公网安备 33010602011771号