要在asp.net实现URL重写,需要组件:URLRewriter.dll (本次测试版本 1.0.1495.18710)
下载地址:
1、URL重写urlrewriter.dll组件下载地址(附完整示例代码)
2、微软URL重写组件urlrewriter.dll下载地址
首先,在<configSections></configSections>节点中添加URL重写配置:
<!-- URL重写 配置重写处理类 -->
<section name="RewriterConfig" type="URLRewriter.Config.RewriterConfigSerializerSectionHandler, URLRewriter"/>
<configuration></configuration>里配置转发地址
<!-- URL重写 将捕获页面转发到实际地址 -->
<RewriterConfig>
<Rules>
<RewriterRule>
<LookFor>~/d(d+).aspx</LookFor>
<SendTo>~/default.aspx?id=$1</SendTo>
</RewriterRule>
<RewriterRule>
<LookFor>~/d(d+).html</LookFor>
<SendTo>~/default.aspx?id=$1</SendTo>
</RewriterRule>
</Rules>
</RewriterConfig>
<!-- URL重写 将捕获页面转发到实际地址 ( 结束 ) -->
然后,在<httpHandlers></httpHandlers>中配置要捕获的HTTP请求页面地址,如下: