URL重写(UrlRewrite)原理

         原理:在Global.asax的Application_BeginRequest 中读取Request.Url 得到请求的URL(View-3.aspx),然后用HttpContext.Current.RewritePath(ReWriteUrl)进行重写(也就是交由另外一个页面处理这个请求)(View.aspx?tid=3格式)
      也可以使用微软的URLRewrite,只要修改配置文件就可以进行URL重写。  

      例如:

           首先建立一个全局应用程序,放在根目录下
           请求管道中的第一个事件

          

 1            protected void Application_BeginRequest(Object sender, EventArgs e)
 2            {
 3             //url重写
 4             string url = Request.AppRelativeCurrentExecutionFilePath;
 5             Match match = Regex.Match(url, @"~/member/BookList2_(\d+).aspx");
 6             if (match.Success)
 7             {
 8                 string categoryId = match.Groups[1].Value;
 9                 Context.RewritePath(@"/member/BookList2.aspx?categoryId="+categoryId);
10             }
11           }
原文地址:https://www.cnblogs.com/hanwenhuazuibang/p/2983784.html