Global.asax的Application_BeginRequest实现url重写无后缀的代码
2018-10-12 13:57
651 查看
利用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重写无后缀的代码
- [置顶] 利用Global.asax的Application_BeginRequest 实现url 重写 无后缀
- 利用Global.asax的Application_BeginRequest 实现url 重写 无后缀
- Global.asax的Application_Error实现错误记录/错误日志的代码
- Global.asax的Application_Error实现错误记录/错误日志的代码
- 转:Global.asax通过Application_BeginRequest()事件实现访问链接的静态地址映射
- 通过Global.asax实现简单的url重写
- 使用Global.asax实现ASP.Net的URL重写
- .net知识系列之七:底层解密(ASP.NET底层之旅,HttpApplication类实例,HttpApplication及Global.asax,实现自定义文件类型处理)
- 采用Global.asax的Application_BeginRequest事件过滤敏感字符
- [置顶] 利用Global.asax的Application_Error实现错误记录,错误日志
- 在Global.asax文件的Application_BeginRequest中获取request请求内容
- 使用Global.asax实现ASP.Net的URL重写
- 通过Global.asax实现简单的url重写
- Global.asax实现URL重写
- 在global.asax中实现URL重写(应用)
- 设置Global.asax实现简单的Url重写
- 通过Global.asax实现简单的url重写
- ASP.NET 用 Global.asax 的Application_BeginRequest 事件过滤恶意提交