url重写


先引用一下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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值