分享web开发知识

注册/登录|最近发布|今日推荐

主页 IT知识网页技术软件开发前端开发代码编程运营维护技术分享教程案例
当前位置:首页 > 代码编程

ASP.NET MVC4通过UrlRewriter配置伪静态,支持html后缀

发布时间:2023-09-06 01:50责任编辑:顾先生关键词:.NET配置MVC

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.cnblogs.com/zhongweiv/archive/2011/10/29/UrlRewriter_IIS.html

ASP.NET MVC4通过UrlRewriter配置伪静态,支持html后缀

原文地址:https://www.cnblogs.com/zhuhaoliang/p/8889515.html

知识推荐

我的编程学习网——分享web前端后端开发技术知识。 垃圾信息处理邮箱 tousu563@163.com 网站地图
icp备案号 闽ICP备2023006418号-8 不良信息举报平台 互联网安全管理备案 Copyright 2023 www.wodecom.cn All Rights Reserved