ASP.net URL重写

来源:百度知道 编辑:UC知道 时间:2024/05/30 11:24:55
想做出像sohu博客那样,url地址最前面是用户自定义的前缀,该怎么做?
有好的答案加分。

URL重写可以通过编程的方式来实现:
1、在asp.net项目中引入程序集URLRewriter,即在网站的Bin文件夹中添加URLRewriter.dll。
2、在web.config中的configuration节点下添加URLRewriter的配置。
<configSections>
<section name="RewriterConfig" type="URLRewriter.Config.RewriterConfigSerializerSectionHandler, URLRewriter"/>
</configSections>
注意:configSections必须是configuration节点下的第一个子元素。
3、在web.config中的system.web节点下添加URLRewriter的配置。
<httpModules>
<add type="URLRewriter.ModuleRewriter, URLRewriter" name="ModuleRewriter"/>
</httpModules>
4、在web.config中的configuration节点下配置url重写的规则。
<RewriterConfig>
<Rules>
<RewriterRule>
<LookFor>~/article/(\d+)/</LookFor>
<SendTo>~/article_info.aspx?articleId=$1</SendTo>
</RewriterRule>
</Rules>
</RewriterConfig>
url重写规则说明:
(1