实例下载地址:http://download.csdn.net/source/910996
非常简单易懂!!!
Intelligencia.UrlRewriter.dll aspx重写为html实例
1、http://urlrewriter.net/ 下载解压缩后把Intelligencia.UrlRewriter.dll 文件添加引用到web工程里。
2.web.config配置:
<configSections> <!--UrlRewriter--> <section name="rewriter" requirePermission="false" type="Intelligencia.UrlRewriter.Configuration.RewriterConfigurationSectionHandler, Intelligencia.UrlRewriter" /> </configSections>
<system.web> <!--UrlRewriter--> <httpModules> <add type="Intelligencia.UrlRewriter.RewriterHttpModule,Intelligencia.UrlRewriter" name="UrlRewriter" /> </httpModules> </system.web> </system.web>
<!--UrlRewriter--> <rewriter> <rewrite url="~/test_([a-zA-Z]+).html$" to="~/Show.aspx?Code=$1" processing="stop" /> </rewriter>
其中: <rewrite url="~/test_([a-zA-Z]+).html$" to="~/Show.aspx?Code=$1" processing="stop" />
若果code= abc的话,最终显示的结果为"虚拟目录名称/test_abc.html" 。如果吧.html替换成 .aspx那就是"虚拟目录名称/test_abc.aspx"
3.IIS配置: 如果是用"虚拟目录名称/test_abc.aspx" 的话,不需要配置IIS. 使用了"虚拟目录名称/test_abc.html" 配置IIS的方法如下: http://urlrewriter.net/index.php/support/installation/windows-server-2003/ 里面的图9不准确,准确的为:

还有第八步中的”untick Verify that file exists.“要看仔细。否则重写HTML就无效。
4:备注
不要在"应用程序扩展"里“添加" .html的映射,否则正常的html将无法访问。
5.在vs2005中,传多个参数应该加&在vs2003中,只用分号就好了
eg.
<RewriterConfig> <Rules> <RewriterRule> <!--CreditNews BackGround update--> <LookFor>~NewsClsManage-(/d*)-(/d*).html</LookFor> <SendTo>~NewsClsManage.aspx?ClassID=$1&flag=$2</SendTo> </RewriterRule> </Rules> </RewriterConfig>
|