Application_BeginRequest(Object sender, EventArgs e)
        {
            string oldUrl = HttpContext.Current.Request.RawUrl ;

            
string pattern = @"^(.+)default/(\d+)\.aspx(\?.*)*$";
            
string replace = "$1default.aspx?id=$2";

            
if(Regex.IsMatch(oldUrl, pattern, RegexOptions.IgnoreCase | RegexOptions.Compiled))
            {
                
string newUrl = Regex.Replace(oldUrl, pattern, replace, RegexOptions.Compiled | RegexOptions.IgnoreCase);
                
this.Context.RewritePath(newUrl);
            }
        }

 

有了上边这段代码,我访问一个类似:.../default/123.aspx 的网址,当然这个网址在我的电脑上不存在,它就会被定向到:.../default.aspx?id=123。

相关文章:

  • 2021-07-21
  • 2022-12-23
  • 2021-08-14
  • 2022-12-23
  • 2021-11-25
  • 2022-12-23
  • 2021-07-07
  • 2022-01-19
猜你喜欢
  • 2021-10-03
  • 2022-12-23
  • 2021-05-04
  • 2022-01-06
  • 2022-12-23
  • 2021-08-04
相关资源
相似解决方案