用户名:
密 码: 记住
您当前的位置:首页 > 网络编程 > Net教程

Global.asax的Application_BeginRequest实现url重写无后缀的代码

时间:2015-01-29  来源:互联网  作者:佚名
利用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>
来顶一下
返回首页
返回首页
推荐资讯
模拟QQ心情图片上传预览示例 模拟QQ心情图片上传预览示例出于安全性能的考虑,目前js端不支持获取本地图片进行预览,
HTML服务器控件和WEB服务器控件的区别和联系介绍 HTML服务器控件和WEB服务器控件的区学习asp.net的时候,视频中总是做例子,这当然是一件好事,可是
相关文章
栏目更新
栏目热门