在網上搜尋一些東西時,突然看到可以直接配置伺服器,然後配置一下 Web.config 檔案就可以實作
僞靜态,于是就試着去實作。用了半天的時間,我終于配置成功了,在這裡分享給大家。
很多文章上面說要下載下傳微軟的 MSDNURLRewriting.msi 軟體,或者是 Url Rewrite2.exe 軟體。我下載下傳下來配置了一下,都沒有成功。
我的配置方法如下:
1.打開IIS伺服器
2.切換到處理程式映射界面
3."添加通配符腳本映射":請求路徑 * ,可執行檔案為:
C:\Windows\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll
,名稱随意。如果是4.0架構用下面這個:
C:\Windows\Microsoft.NET\Framework\v4.0.30319\aspnet_isapi.dll
這裡很重要,是以我用了紅色字型。
4.将內建模式改為經典模式
【以下兩個步驟 一般可以省略】
5.右邊"添加腳本映射":請求路徑 .html ,可執行檔案選擇
C:\Windows\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll ,如果是4.0,則為
C:\Windows\Microsoft.NET\Framework\v4.0.30319\aspnet_isapi.dll,名稱随意;
(注意:如果你的系統是32位的。請選擇 Framework,如果64位,請選Framework64。這個關鍵到後面的僞靜态問題,慎重!!)
6."添加托管處理程式":請求路徑 * ,可執行檔案:System.Web.UI.PageHandlerFactory,名稱随意;
打開站點切換到功能試圖,找到 "IIS(伺服器元件)"->"子產品",輕按兩下之後,在打開視窗右側的操作欄目中,
點選"添加托管子產品",名稱随意,類型URLRewriter.ModuleRewriter,并且把"僅針對向asp.net 應用程式或
托管處理程式送出請求調用" 選中
7.配置Web.config檔案
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<!--必要參數-->
<configSections>
<section name="RewriterConfig" type="URLRewriter.Config.RewriterConfigSerializerSectionHandler, URLRewriter" />
</configSections>
<!--必要參數-->
<RewriterConfig>
<Rules>
<!--<RewriterRule>
<LookFor>~/web/new/type/(.[0-9]*)\.html</LookFor>
<SendTo>~/web/new.aspx?id=$1</SendTo>
</RewriterRule>-->
<RewriterRule>
<!--URL裡面要寫的-->
<LookFor>~/Default/(.[0-9]*)/.html</LookFor>
<!--要到的實際動态頁面-->
<SendTo>~/Default.aspx?id=$1</SendTo>
</RewriterRule>
</Rules>
</RewriterConfig>
<system.web>
<!--必要參數-->
<httpHandlers>
<add verb="*" path="*.aspx" type="URLRewriter.RewriterFactoryHandler, URLRewriter" />
<add verb="*" path="*.html" type="URLRewriter.RewriterFactoryHandler, URLRewriter" />
</httpHandlers>
<compilation debug="true" targetFramework="4.0">
<!--為了使真正的html頁面也能正常使用-->
<buildProviders>
<add extension=".html" type="System.Web.Compilation.PageBuildProvider" />
</buildProviders>
</compilation>
</system.web>
<system.webServer>
<validation validateIntegratedModeConfiguration="false" />
<!--禁止驗證內建模式-->
</system.webServer>
</configuration>
接下來通路Default/1/.html
好了,這就配置完成了。