其實一直有這個疑問,為什么人家.net 寫的網站為什么后綴能變成.html來顯示?今天終於明白了,答案:UrlRewrite
步驟:添加URLRewriter.dll ,網上自己下載,還有一個ActionlessForm.dll,是處理post數據的。然后在web.config中配置頁面信息,具體如下:
1、往<configuration>節點中添加
<configSections><section name="RewriterConfig" type="URLRewriter.Config.RewriterConfigSerializerSectionHandler, URLRewriter"/></configSections>;
2、在<configuration>下的<system.web>節點中添加
<httpModules>
<add type="URLRewriter.ModuleRewriter, URLRewriter" name="ModuleRewriter"/>
</httpModules>
3、開始在<configuration>下寫Rewriter配置信息,url信息用正則表達式表示
<RewriterConfig>
<Rules>
<!-- 規則,可以使用正則表達式 -->
<RewriterRule>
<LookFor>~/index.html</LookFor>
<SendTo>~/Index.aspx</SendTo>
</RewriterRule>
<RewriterRule>
<LookFor>~/News.html</LookFor>
<SendTo>~/News.aspx</SendTo>
</RewriterRule>
<RewriterRule>
<LookFor>~/NewsShow_(\d{1,4})\.html</LookFor>
<SendTo>~/NewsShow.aspx?id=$1</SendTo>
</RewriterRule>
<RewriterRule>
<LookFor>~/wjProduct-(\d{1,6})-(\d{1,6})\.html</LookFor>
<SendTo>~/wjProduct.aspx?page=$1&Menu_ID=$2</SendTo> //第一個參數用$1;第二個參數用$2... 參數中間加&
</RewriterRule>
。。。
。。。
</Rules>
</RewriterConfig>
4、接下來就是每個url的寫法了,比如你在index.aspx頁面的主頁為index.html ,但是真正發送請求出去的是index.aspx,其他也一樣道理。再在項目的屬性中設置啟動為index.html;這樣一運行就執行了index.html。
注意:這樣重寫可能會致使有些路徑錯亂,如圖片路徑。畢竟你是在項目都弄完后才來rewrite的,所以要小心。