標籤:style blog http io ar 使用 sp for 檔案
在Web.config檔案中添加規則:
<configSections></configSections>//=============下面是添加的代碼===============<RewriterConfig> <Rules> <!-- Blog 內容顯示程式規則 --> <RewriterRule> <LookFor>~/(\d{4})/(\d{2})/(\d{2})\.aspx</LookFor> <SendTo>~/ShowBlogContent.aspx?year=$1&month=$2&day=$3</SendTo> </RewriterRule> <RewriterRule> <LookFor>~/(\d{4})/(\d{2})/Default\.aspx</LookFor> <SendTo><![CDATA[~/ShowBlogContent.aspx?year=$1&month=$2]]></SendTo> </RewriterRule> <RewriterRule> <LookFor>~/(\d{4})/Default\.aspx</LookFor> <SendTo>~/ShowBlogContent.aspx?year=$1</SendTo> </RewriterRule> </Rules></RewriterConfig>//=============上面是添加的代碼===============<system.web></system.web>
這些重寫規則表明了Regex的功能。在第一個規則中,我們使用模式 (\d{4})/(\d{2})/(\d{2})\.aspx 尋找 URL。在簡明英語中,它對應了這樣一個字串:首先是四個數字,後跟一個斜杠,然後是兩個數字,後跟一個斜杠,然後再跟兩個數字,最後是一個 .aspx。每個數字組周圍的括弧非常重要,通過它可以在相應的 <SendTo> 屬性中引用這些括弧內的匹配字元。 特別是,我們可以針對第一、第二和第三個括弧組分別使用 $1、$2 和 $3 引用回括弧內的匹配組。
注意:由於 Web.config 檔案採用 XML 格式,但是必須對元素文字部分中的字元(如 &、< 和 >)進行轉義。在第一個規則的 <SendTo> 元素中,& 被轉義為 &。在第二個規則的 <SendTo> 中使用了另外一種技術(使用 <![CDATA[...]]> 元素),無需對內部的內容進行轉義。可以使用兩種方法中的任何一種,並且都會得到相同的結果。
在工程中引用Dll檔案URLRewriter.dll。
:http://files.cnblogs.com/ainy360/URLRewriter.rar
ASP.NET中URL重新導向的實現