Url重写的简单方法

  • Post author:
  • Post category:其他

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

        string pattern = @”^(.+)News(/d+)/.html(/?.*)*$”;
        string replace = “$1NewsDetails.aspx?NID=$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);
        }

}
 


版权声明:本文为ahhisoft原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。