源码网商城,靠谱的源码在线交易网站 我的订单 购物车 帮助

源码网商城

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

  • 时间:2021-11-15 10:22 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要:Global.asax的Application_BeginRequest实现url重写无后缀的代码
利用Global.asax的Application_BeginRequest 实现url 重写 无后缀
[u]复制代码[/u] 代码如下:
<%@ 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>
  • 全部评论(0)
联系客服
客服电话:
400-000-3129
微信版

扫一扫进微信版
返回顶部