ASP.NET MVC4通過UrlRewriter配置偽靜態,支持html后綴
ASP.NET MVC4通過UrlRewriter配置偽靜態
通過UrlRewriter在MVC4中配置偽靜態在網上都有很多資料,本篇博客主要是把項目中使用到的通過UrlRewriter配置偽靜態提取出來,方便自己以后查看,同樣對需要該功能的網友提供思路。
第一:下載UrlRewriter.dll文件,并引用到項目中
第二:配置Web.config
依次在下面節點中添加UrlRewriter相關的子節點
1. <configSections>
2. <section name="CustomConfiguration" type="URLRewriter.Config.UrlsSection, URLRewriter"/>
3. </configSections>
1. <system.web>
2. <httpModules>
3. <add type="URLRewriter.RewriterModule, URLRewriter" name="RewriterModule"/>
4. </httpModules>
5. </system.web>
1. <system.webServer>
2. <modules runAllManagedModulesForAllRequests="true">
3. <add name="URLRewriter" type="URLRewriter.RewriterModule" preCondition="managedHandler"/>
4. </modules>
5. </system.webServer>
第三:配置RouteConfig.cs
1. public static void RegisterRoutes(RouteCollection routes)
2. {
3. routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
4.
5. routes.MapRoute(
6. "Action1Html", // action偽靜態
7. "{controller}/{action}.html",// 帶有參數的 URL
8. new { controller = "Home", action = "Index", id = UrlParameter.Optional }// 參數默認值
9. );
10. routes.MapRoute(
11. "IDHtml", // id偽靜態
12. "{controller}/{action}/{id}.html",// 帶有參數的 URL
13. new { controller = "Home", action = "Index", id = UrlParameter.Optional }// 參數默認值
14. );
15.
16. routes.MapRoute(
17. "ActionHtml", // action偽靜態
18. "{controller}/{action}.html/{id}",// 帶有參數的 URL
19. new { controller = "Home", action = "Index", id = UrlParameter.Optional }// 參數默認值
20. );
21.
22. routes.MapRoute(
23. "ControllerHtml", // controller偽靜態
24. "{controller}.html/{action}/{id}",// 帶有參數的 URL
25. new { controller = "Home", action = "Index", id = UrlParameter.Optional }// 參數默認值
26. );
27. routes.MapRoute(
28. "Root",
29. "",
30. new { controller = "Home", action = "Index", id = UrlParameter.Optional });//根目錄匹配
31.
32. routes.MapRoute(
33. name: "Default",
34. url: "{controller}/{action}/{id}",
35. defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
36. );
37. }
38. }
第四:配置IIS
在IIS中新建網站(端口號8111)
直接運行http://localhost:8111/
錯誤截圖

配置方法:

二、添加通配符腳本映射,選擇:C:\Windows\Microsoft.NET\Framework\v4.0.30319\aspnet_isapi.dll

三、找到和網站相對的連接池,選擇framework 4.0 經典模式


四、選擇應用程序連接池,高級設置,啟用32位應用程序,設為true

我的個人簡介:http://www.chinaebei.com/condition/Cond/35.html
我的更多信息:http://www.chinaebei.com/condition.html
參考文章:
ASP.NET MVC4通過UrlRewriter配置偽靜態
http://blog.csdn.net/just_shunjian/article/details/51132866
.NET4.0下網站應用程序用UrlRewriter.dll重寫無后綴路徑 (在IIS7.5中的配置方法)
http://www.rzrgm.cn/zhongweiv/archive/2011/10/29/UrlRewriter_IIS.html
浙公網安備 33010602011771號