先引用一下UrlRewriter.dll(实例中包含).在web.config中添加配置(由于"<"及">"会被HTML转换,下列"<",">"改用全角字符
<configSections>
<section name="RewriterConfig" type="URLRewriter.Config.RewriterConfigSerializerSectionHandler, URLRewriter"/>
</configSections>
<RewriterConfig>
<Rules>
<RewriterRule>
<LookFor>~/news-detail-(/d*).aspx</LookFor> <!--获取来方URL-->
<SendTo>~/Default.aspx?id=$1</SendTo> <!--根据规则访问实际页面-->
</RewriterRule>
<RewriterRule>
<LookFor>~/Default-(/d*).aspx</LookFor>
<SendTo>~/Default.aspx?id=$1</SendTo>
</RewriterRule>
<RewriterRule>
<LookFor>~/Default(/d*).html</LookFor>
<SendTo>~/Default.aspx?id=$1</SendTo>
</RewriterRule>
<RewriterRule>
<LookFor>~/(/d{4})/(/d{2})/(/d{2})/default.aspx</LookFor>
<SendTo>~/default.aspx?year=$1&month=$2&day=$3</SendTo>
</RewriterRule>
<RewriterRule>
<LookFor>~/(/d{4})/(/d{2})/Default.aspx</LookFor>
<SendTo>~/default.aspx?year=$1&month=$2</SendTo>
</RewriterRule>
<RewriterRule>
<LookFor>~/(/d{4})/Default.aspx</LookFor>
<SendTo>~/default.aspx?year=$1</SendTo>
</RewriterRule>
</Rules>
</RewriterConfig>
<system.web>
<httpModules>
<add type="URLRewriter.ModuleRewriter, URLRewriter" name="ModuleRewriter"/>
</httpModules>
<httpHandlers>
<add verb="*" path="*.aspx" type="URLRewriter.RewriterFactoryHandler, URLRewriter"/>
<add verb="*" path="*.html" type="URLRewriter.RewriterFactoryHandler, URLRewriter"/><!--如需重写为HTML需添加此行-->
</httpHandlers>
</system.web>
本文来源于:C# .net学习之旅 原文地址:http://www.li-gang.cn/200903/29.html