电竞比分网-中国电竞赛事及体育赛事平台

分享

.net實(shí)現(xiàn)URL重寫,偽靜態(tài)。IIS7直接支持重寫模塊

 wangn 2010-09-16

一、獲得Mircosoft URLRewriter.dll:
獲得Mircosoft URLRewriter.dll可以到http://www.microsoft.com/china/msdn/library/webservices/asp.net/URLRewriting.mspx?mfr=true
下載完畢后,導(dǎo)入工程,我這里沒有對(duì)該工程做任何修改,保留了原來(lái)的重寫方式,然后直接在VS2005里面生成.dll文件就可以了。

二、使用該dll文件:添加引用,搞定。

三、頁(yè)面方面的設(shè)計(jì),這里不在贅述了。

四、web.config的配置
這部是非常關(guān)鍵的,也是靜態(tài)化能否成功的關(guān)鍵。
<?xml version="1.0"?>
<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>
<LookFor>~/web/index.html</LookFor>
<SendTo>~/web/index.aspx</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"/></system.web>
</configuration>

這里簡(jiǎn)單介紹一下:
<RewriterConfig>
<Rules>
<RewriterRule>
<LookFor>要查找的模式</LookFor>
<SendTo>要用來(lái)替換模式的字符串</SendTo>
</RewriterRule>
<RewriterRule>
<LookFor>要查找的模式</LookFor>
<SendTo>要用來(lái)替換模式的字符串</SendTo>
</RewriterRule>
</Rules>
</RewriterConfig>
httpHandlers的設(shè)置主要是配合IIS將請(qǐng)求重新定義處理,這里也比較關(guān)鍵,如果不存在合理的httpHandlers,那么,訪問肯定會(huì)失敗的。
關(guān)于正則表達(dá)式,可以到百度里搜索:"常用正則表達(dá)式",會(huì)有很多。

五、配置IIS解析.html文件
右鍵點(diǎn)我的電腦-->管理-->展開'服務(wù)和應(yīng)用程序'-->internet信息服務(wù)-->找到你共享的目錄-->右鍵點(diǎn)擊屬性 -->點(diǎn)擊'配置'-->映射下面 -->找到.aspx的可執(zhí)行文件路徑 復(fù)制路徑-->粘貼路徑-->擴(kuò)展名為".html"-->然后把檢查文件是否存在的勾去掉這樣就可以了,如果遇到“確定”按鈕失效,可以用鍵盤事件編輯路徑即可解決。

    本站是提供個(gè)人知識(shí)管理的網(wǎng)絡(luò)存儲(chǔ)空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點(diǎn)。請(qǐng)注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購(gòu)買等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊一鍵舉報(bào)。
    轉(zhuǎn)藏 分享 獻(xiàn)花(0

    0條評(píng)論

    發(fā)表

    請(qǐng)遵守用戶 評(píng)論公約

    類似文章 更多