URLRewriter最簡單入門介紹 URLRewriter相關資源

來源:互聯網
上載者:User

1. URLRewriter 相關資源:
http://download.microsoft.com/download/0/4/6/0463611e-a3f9-490d-a08c-877a83b797cf/MSDNURLRewriting.msi
http://msdn.microsoft.com/zh-cn/library/ms972974.aspx
http://blog.csdn.net/chenghp/archive/2007/04/10/1559212.aspx

2. URLRewriter 次層網域的實現:
http://www.cnblogs.com/jzywh/archive/2006/02/20/seconddomainurlrewriter.html
http://www.cnblogs.com/jzywh/archive/2005/09/29/246650.html

3. 適用場合 IIS相關配置:

配置好後,查看日誌看到的狀態都是200,IIS直接認為這個檔案是存在的了,
而不是301,或302,這在某些情況下可能會不適用,比如:搜尋引擎最佳化時目錄或檔案調整。

預設只支援.net格式的重新導向 比如:.aspx格式的重新導向。
如:show_12_yongfa365.aspx --> show.aspx?id=12&name=yonga365

如果想實現,*.html這樣的格式(一般我們就用這種方法實現.net 偽靜態)
如:show_12_yongfa365.html --> show.aspx?id=12&name=yonga365

得在網站裡加上相關“應用程式擴充”
添加方法:右擊相關網站-->屬性-->主目錄-->配置-->映射-->
在裡面找到副檔名是.aspx的記錄,雙擊,複製裡面的可執行檔裡的內容,關閉
回到了應用程式配置裡,點添加,粘貼剛才複製的地址,副檔名裡輸入".html",把“確認檔案是否存在”的勾去掉。
OK,IIS上相關配置就配好了。

4.下載相關檔案:

請從此下載UrlRewriter組件。安裝,把安裝目錄下裡的 UrlRewriter.dll copy 到你的項目 bin 目錄下。

5.配置 Web.config:

在<configuration>標籤裡加上:

<configSections>
<section name="RewriterConfig" type="URLRewriter.Config.RewriterConfigSerializerSectionHandler, URLRewriter" />
</configSections>

<!--URLRewriter重寫規則,不會Regex的到網上找找,柳永法當時在車上兩小時看完相關文檔,感覺就看會了。-->
<RewriterConfig>
<Rules>
<RewriterRule>
<LookFor>~/(\d+).aspx</LookFor>
<SendTo>~/Default.aspx?page=$1</SendTo>
</RewriterRule>
</Rules>
</RewriterConfig>

在<system.web>標籤裡加上:

<httpModules>
<add type="URLRewriter.ModuleRewriter, URLRewriter" name="ModuleRewriter" />
</httpModules>
<!--
<httpHandlers>
<add verb="*" path="*.aspx" type="URLRewriter.RewriterFactoryHandler, URLRewriter" />
<add verb="*" path="*.html" type="URLRewriter.RewriterFactoryHandler, URLRewriter" />
</httpHandlers>
-->

6. 加入表單回傳保持的組件:
如果你的頁面有回傳。比如說放了DataGrid 或 GridView等,有分頁的會出問題,解決方案:
在原來你下載的項目裡找到 ActionlessForm.dll 放到你的項目 bin 目錄下。

然後在你的這個頁面中加入:
<%@ Register TagPrefix="skm" Namespace="ActionlessForm" Assembly="ActionlessForm" %>
再把你的<Form...>改為:
<skm:Form id="你的表單名" method="post" runat="server">
.....
</skm:Form>

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.