主页 > 知识库 > Global.asax的Application_BeginRequest实现url重写无后缀的代码

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

热门标签:十堰正规电销机器人系统 手机地图标注如何删除 怎么给超市做地图标注入驻店 外呼系统代理品牌 巫师3为什么地图标注的财宝没有 世纪佳缘地图标注怎么去掉 宁波自动外呼系统代理 办理400电话证件 外呼系统费用一年
利用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>
您可能感兴趣的文章:
  • asp.net 在global中拦截404错误的实现方法
  • Global.cs中自动获取未处理的异常
  • 在Global.asax文件里实现通用防SQL注入漏洞程序(适应于post/get请求)
  • Global.asax取绝对路径的方法
  • Global.asax取物理路径/取绝对路径具体方法
  • Global.asax的Application_Error实现错误记录/错误日志的代码
  • c#定时器和global实现自动job示例
  • ASP.net全局程序文件Global.asax用法分析
  • ASP.NET中Global和URLReWrite用法
  • 在C#中global关键字的作用及其用法

标签:平凉 山西 景德镇 通辽 牡丹江 嘉兴 泰州 天门

巨人网络通讯声明:本文标题《Global.asax的Application_BeginRequest实现url重写无后缀的代码》,本文关键词  Global.asax,的,Application,BeginRequest,;如发现本文内容存在版权问题,烦请提供相关信息告之我们,我们将及时沟通与处理。本站内容系统采集于网络,涉及言论、版权与本站无关。
  • 相关文章
  • 下面列出与本文章《Global.asax的Application_BeginRequest实现url重写无后缀的代码》相关的同类信息!
  • 本页收集关于Global.asax的Application_BeginRequest实现url重写无后缀的代码的相关信息资讯供网民参考!
  • 推荐文章