手机
当前位置:查字典教程网 >编程开发 >asp.net教程 >Global.asax的Application_BeginRequest实现url重写无后缀的代码
Global.asax的Application_BeginRequest实现url重写无后缀的代码
摘要:利用Global.asax的Application_BeginRequest实现url重写无后缀复制代码代码如下:voidApplicati...

利用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(1, reg.Match(oldUrl).ToString().LastIndexOf(".") - 1);

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(1);

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(7);

Context.RewritePath("~/Index.aspx?id=" + id);

}

}

</script>

【Global.asax的Application_BeginRequest实现url重写无后缀的代码】相关文章:

asp.net下定制日期输出格式的代码

asp.net中利用ashx实现图片防盗链代码

asp.net Execl的添加,更新操作实现代码

asp.net实现C#绘制太极图的方法

DataList 中动态绑定服务器子控件的代码

.Net 文本框实现内容提示的实例代码

ASP.NET Ajax级联DropDownList实现代码

asp.net实现文件无刷新上传方法汇总

asp.net下实现URL重写技术的代码

asp.net实现md5加密

精品推荐
分类导航