asp.net 页面url重写
来源:互联网 发布:提醒软件 编辑:程序博客网 时间:2024/05/04 05:33
asp.net 页面url重写
不更改情况下,页面路径为index.aspx?id=1,现在输入页面路径index/1时,也能访问到页面,这一过程叫做url重写
①:在一个类里制定路径重写规则,以下为自定义UrlRewriterFilter类,需要继承接口IHttpModule
②:在配置文件里面configuration节点里进行配置(如果自定义类是在另一个类库里面写的,则需要将该类库的.dll文件生成路径改为和启动项.dll文件路径一致)
另外,asp.net的url重写还可以直接在网站发布的时候,进行IIS 选择url重写功能进行配置
第一步:
using System;using System .Collections . Generic;using System .Linq;using System .Text;using System .Threading . Tasks;namespace HttpModule{ using System. Web; using System. Text .RegularExpressions; public class UrlRewriterFilter :IHttpModule { public void Dispose() { throw new NotImplementedException (); } /// <summary> /// 负责在第一个管道事件上注册一个重写 index/1的url为 index.aspx?id=1 /// </summary> /// <param name= "context" ></param> public void Init( HttpApplication context) { context . BeginRequest+= context_BeginRequest; } void context_BeginRequest( object sender, EventArgs e) { //01.获取当前请求的原始url index/1 string url = HttpContext. Current .Request . RawUrl; //02.将当前url重写 // 定义一个正则表达式来检查当前发送过来的url 是否为我要重写的index页面路径 Regex reg = new Regex ("/index/(.*)" ); if (reg. IsMatch(url)) { string newUrl = reg .Replace(url, "/index.aspx?id=$1" ); HttpContext .Current . RewritePath(newUrl); } } }}
第二步:
< system.webServer > < modules > < add name =" indexUrlRewrite " type =" HttpModule.UrlRewriterFilter "/> </ modules > </ system.webServer >
0 0
- asp.net 页面url重写
- ASP.NET URL重写
- ASP.NET URL重写
- URL 重写(Asp.Net)
- asp.net url重写
- asp.net url重写
- url重写 asp.net
- asp.net url重写
- ASP.NET重写URL
- asp.net url重写
- asp.net url重写
- asp.net url 重写
- asp.net URL重写
- ASP.NET URL重写
- ASP.NET URL重写
- asp.net重写URL
- asp.net Url重写
- asp.net url重写
- 题目1055:数组逆置
- 微信分享到朋友圈
- swystoj(OpenCV(0272))
- 【HTML】3.超链接标签
- 彻底解决 webpack 打包文件体积过大
- asp.net 页面url重写
- centos7 yum 更新出现 [Errno 14] HTTP Error 404
- activity劫持学习与复现
- 将有序表转化为二叉搜索树
- 五、Balloon Comes!
- Docker端口映射实例
- Andoid 7.0调用系统拍照的正确用法
- HTML元素类型详解
- 14. Longest Common Prefix