轉載自 : 瓶水相逢.Net

常常有些人會問如何隱藏 Querystring,原因是 Querystring 裡面包含一些參數不想被使用者知道。以下文章就介紹如何使用 UrlRewriter.NET  套件,來幫助我們實現 Url Rewriting 將 Querystring  隱藏起來。

</configuration>

  <configSections>
    <section name="rewriter" 
             requirePermission="false" 
             type="Intelligencia.UrlRewriter.Configuration.RewriterConfigurationSectionHandler, Intelligencia.UrlRewriter"/>
  </configSections>
 
  <system.web>
    <httpModules>
      <add name="UrlRewriter" 
           type="Intelligencia.UrlRewriter.RewriterHttpModule, Intelligencia.UrlRewriter"/>
    </httpModules>
  </system.web>
 
  <rewriter>
    <rewrite url="~/Books/(\d+)/Default.aspx" to="~/Books.aspx?bookID=$1"/>
  </rewriter>
 
</configuration>

其中比較注意的是 <rewriter> 區塊的部分,url 表示來源網址,to 表示目的網址。舉例來說,你的網址是 Books/1234/Default.aspx 時,UrlRewiter 就幫你 Url 轉向 Books.aspx?bookID=1234。其中 (\d+) 是一種 Regular Expression(Regex)的表示方法,表示由 0-9 組合而成的字串組合,$1 則代表 url 符合 Regex 的字串變數。當你有多組 Regex,則就會有 $1、$2、$3...以此類推。

arrow
arrow
    全站熱搜
    創作者介紹
    創作者 11 的頭像
    11

    冠霖的部落格

    11 發表在 痞客邦 留言(0) 人氣()