URL重寫(UrlRewrite)原理

來源:互聯網
上載者:User

         原理:在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           }

 

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.