Global.asax的Application_BeginRequest实现url重写无后缀的代码
本文为大家详细介绍下利用Global.asax的Application_BeginRequest 实现url重写其无后缀,具体核心代码如下,有需求的朋友可以参考下,希望对大家有所帮助
利用Global.asax的Application_BeginRequest 实现url 重写 无后缀
代码如下:
<%@ Application Language="C#" %> <script RunAt="server">
void Application_BeginRequest(object sender, EventArgs e)
{
string oldUrl = System.Web.HttpContext.Current.Request.RawUrl; //获取初始url //~/123.aspx → ~/Index.aspx?id=123
Regex reg = new Regex(@"^\/\d+\.html");
if (reg.IsMatch(oldUrl))
{
string id = reg.Match(oldUrl).ToString().Substring(, reg.Match(oldUrl).ToString().LastIndexOf(".") - );
Context.RewritePath("~/Index.aspx?id=" + id);
} //~/123 → ~/Index.aspx?id=123
Regex reg1 = new Regex(@"^\/\d+$");
if (reg1.IsMatch(oldUrl))
{
string id = reg1.Match(oldUrl).ToString().Substring();
Context.RewritePath("~/Index.aspx?id=" + id);
} //~/index/123 → ~/Index.aspx?id=123
Regex reg3 = new Regex(@"^\/index\/\d+$");
if (reg3.IsMatch(oldUrl))
{
string id = reg3.Match(oldUrl).ToString().Substring();
Context.RewritePath("~/Index.aspx?id=" + id);
}
} </script>
Global.asax的Application_BeginRequest实现url重写无后缀的代码的更多相关文章
- [置顶] 利用Global.asax的Application_BeginRequest 实现url 重写 无后缀
利用Global.asax的Application_BeginRequest 实现url 重写 无后缀 <%@ Application Language="C#" %> ...
- 使用Global.asax的Application_BeginRequest事件过滤客户端XSS恶意脚本提交
XSS攻击全称跨站脚本攻击(Cross Site Scripting),是一种在web应用中的计算机安全漏洞,它允许恶意web用户将代码(如HTML代码和客户端脚本)植入到提供给其它用户使用的页面中. ...
- 采用Global.asax的Application_BeginRequest事件过滤敏感字符
1.特殊字符过滤公共类ProcessRequest.cs using System.Web.UI; using System.Web.UI.WebControls; using System.Web. ...
- .NET4.0下网站应用法度用UrlRewriter.dll重写无后缀路径 (在IIS7.5中的设备办法)
.NET4.0下网站应用法度用UrlRewriter.dll重写无后缀路径 在IIS中新建网站(端标语8111) 直接运行http://localhost:8111/ 设备办法: 二.添加通配符脚本映 ...
- iis5.1/6.0/7.0+ 配置url重写 无扩展名伪静态
原文链接:http://www.cnblogs.com/diose/archive/2013/02/21/2920324.html 最近在搞url重写 遇到iis 无扩展名及html映射问题 供后人查 ...
- IIS7下.NET4.0 网站UrlRewriter.dll重写无后缀路径 失效
解决方法: 1.添加通配符脚本映射,选择:C:\Windows\Microsoft.NET\Framework\v4.0.30319\aspnet_isapi.dll 2.找到和网站相对的连接池,选择 ...
- 使用微软URLRewriter.dll的url实现任意后缀名重写
<?xml version="1.0"?> <!--先引用URLRewriter.dll,放置于Bin目录--> <configuration> ...
- C# WebService URL重写
背景 有时候我们会有这样的需求,将 WebService URL 中的 asmx 后缀去掉:或者我们要模拟普通 Web 的 URL,接口名称直接拼接在 URL 中.这些情况我们都要用到URL重写. 关 ...
- 【C#】 用Route进行URL重写
在.NET Framework 4中,微软推出了Route机制.这种机制不仅在MVC中大量运用,在WebForm中也可以使用. 和Contex.RewritePath()一样,Route功能也是写在G ...
随机推荐
- Android——修改Button样式,动态修改Button中的图片大小
原文地址: http://www.cnblogs.com/gzggyy/archive/2013/05/17/3083218.html http://www.xuebuyuan.com/2173740 ...
- 计算机名、主机名、用户账户名与NetBIOS名有什么区别
1.计算机名:右击“我的电脑”,选择“属性”,在“系统属性”对话框的“计算机名”选项卡里,可以设置计算机名.计算机名是对域(或工作组)中的计算机的标识,如果你的计算机名设置为“至清水”,则在网上邻居里 ...
- RavenDb学习(二)简单的增删查改
在上一节当中已经介绍了RavenDb的文档设计模式,这一节我们要具体讲一讲如何使用api去访问RavenDb .连接RavenDb var documentStore = new DocumentSt ...
- WebRTC 源码分析(四):VideoCRE 与内存抖动优化
WebRTC 是个宝,初窥这部分代码时就被它的 Capturer 类的设计惊艳到了,仔细品鉴后越发佩服起来,里面简直填了太多坑了,如此宝贝,如不能为我所用,岂非一大憾事!而前三篇的解读,正是为了今天能 ...
- LibreOffice openoffice 区别
LibreOffice的初始版本号码被设置为与OpenOffice.org一致,故初始发布(2010年)即为第三版,并不存在第二版.第一版. 后来,甲骨文宣布停止OpenOffice.org的商业支持 ...
- 实现JTextfield 的右键 复制、剪切、粘贴功能。
http://leagion.iteye.com/blog/572730 ——————————————————————————————————————————————————————————————— ...
- R语言:读取数据
主要学习如何把几种常用的数据格式导入到R中进行处理,并简单介绍如何把R中的数据保存为R数据格式和csv文件. 1.保存和加载R的数据(与R.data的交互:save()函数和load()函数)a &l ...
- 安卓程序代写 网上程序代写[原]BluetoothServerSocket详解
一. BluetoorhServerSocket简介 1. 继承关系 public final class BluetoothServerSocket extends Object implement ...
- Linux的内存管理
Linux的内存管理,实际上跟windows的内存管理有很相像的地方,都是用虚拟内存这个的概念,说到这里不得不骂MS,为什么在很多时候还有很大的物理内存的时候,却还是用到了pagefile. 所以才经 ...
- backup & restore On Ubuntu
详见:https://help.ubuntu.com/community/BackupYourSystem/TAR 在 使用Ubuntu之前,相信很多人都有过使用Windows系统的经历.如果你备份过 ...