//先到http://urlrewriter.net/裡面的Doenload 下載一個dll

 

 //加入參考在Release裡的Intelligencia.UrlRewriter.dll 

   

 //接著把以下這些加到Web.config檔裡

   

<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>

 

    //以下這邊是重點,利用Regular Express來把某個網址URL對應到另一個實體的檔案

    //像下面就是我把輸入在URL根目錄後面的字當成ID傳到Cool.aspx裡面

    //打http://welkingunther.pixnet.net/naruto的話就會把naruto傳到Cool.aspx裡面

    //打http://welkingunther.pixnet.net/easy/firebomb的話就會把firebomb傳到Cool.aspx裡面

    //$1是取前面的RegEx的符合值,以()來分的話還可用$2、$3來照順序取

    //在Cool.aspx裡面就用Request.QueryString["ID"].ToString()來接參數就可

    <rewrite url="~/([0-9a-zA-Z]+)$" to="~/welkingunther/Cool.aspx?ID=$1" />

    <rewrite url="~/([0-9a-zA-Z]*)/$" to="~/welkingunther/Cool.aspx?ID=$1" />

    <rewrite url="~/easy/([0-9a-zA-Z]+)$" to="~/welkingunther/Cool.aspx?ID=$1" />

 

  </rewriter>

 

 

</configuration>

 

 

另外,如果要放到IIS上,要設定,不然會出現404找不到檔案喔(但是在VisualStudio的虛擬IIS卻可跑)

 

開啟IIS點選網站右鍵內容主目錄設定插入

瀏覽選C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll

 

然後取消這個的勾勾"確認該檔案是否存在"

arrow
arrow
    全站熱搜

    welkingunther 發表在 痞客邦 留言(2) 人氣()