ASP.NET URL重写

需要一个类库:URLRewriter.dll (本次测试版本 1.0.1495.18710)

官网下载地址:http://download.microsoft.com/download/0/4/6/0463611e-a3f9-490d-a08c-877a83b797cf/MSDNURLRewriting.msi

  

    <configSections>    </configSections>节点里添加URL重写配置

      <!-- URL重写 配置重写处理类  -->
<section name="RewriterConfig" type="URLRewriter.Config.RewriterConfigSerializerSectionHandler, URLRewriter" />

<configuration></configuration>里配置转发地址

 

 
 1   <!-- URL重写 将捕获页面转发到实际地址  -->
2 <RewriterConfig>
3 <Rules>
4 <RewriterRule>
5 <LookFor>~/d(\d+)\.aspx</LookFor>
6 <SendTo>~/default.aspx?id=$1</SendTo>
7 </RewriterRule>
8 <RewriterRule>
9 <LookFor>~/d(\d+)\.html</LookFor>
10 <SendTo>~/default.aspx?id=$1</SendTo>
11 </RewriterRule>
12 </Rules>
13 </RewriterConfig>
14 <!-- URL重写 将捕获页面转发到实际地址 ( 结束 ) -->
<httpHandlers></httpHandlers>里配置要捕获的HTTP请求页面地址

 

1         <!-- URL重写 需要捕获*.aspx页面 -->
2 <add verb="*" path="/WebSite3/*.aspx" type="URLRewriter.RewriterFactoryHandler, URLRewriter" />
3 <add verb="*" path="/WebSite3/*.html" type="URLRewriter.RewriterFactoryHandler, URLRewriter" />
 

作者: 张浩华   发布时间: 2011-03-18