- 5
- 0
- 约1.54万字
- 约 21页
- 2017-08-24 发布于河南
- 举报
1、在Web.Config的system.web和/system.web添加以下节点:
?
httpHandlers????? add verb=* path=*.aspx type=URLRewriter.RewriterFactoryHandler, URLRewriter /????? add verb=* path=*.html type=URLRewriter.RewriterFactoryHandler, URLRewriter /?/httpHandlers
?
2、在Web.Config的configuration和/configuration添加以下节点:
?
?configSections??? section name=RewriterConfig type=URLRewriter.Config.RewriterConfigSerializerSectionHandler, URLRewriter /? /configSections
? RewriterConfig??? Rules????? RewriterRule??????? LookFor~/d(\d+)\.html/LookFor??????? SendTo~/Default.aspx?MyID=$1/SendTo????? /RewriterRule??? /Rules? /RewriterConfig
?
设置完以上两个步骤,就基本可以运行了,其中RewriterRule/标签里面就是重写的一个模块,LookFor/里面的是重写后的地址,而SendTo/则是原地址。
?
3、配置IIS解析.html文件IIS配置:网站-属性-虚拟目录-配置(G)...-映射-通配符应用程序映射-添加可执行文件:c:\windows\\framework\v2.0.50727\aspnet_isapi.dll扩展名为:.html
确认文件是否存在:不选.
4、以上配置好之后就可以通过以下方式来访问了
例如用户输入 hostname/d11.html,服务器会把他重写为http://hostname/default.aspx?id=11。换句话说用户输入http://hostname/d11.html,实际访问的是http://hostname/default.aspx?id=11
当然,程序直接生成静态页面可以实现的? 但是那样要生成很多这种页面以及文件夹? 而且在数据量大的情况下生成是很浪费时间的? 在这种情况下就要实现url重写了,当然就很多种方法? 下面介绍的是微软的URLRewriter方法? 1.首先下载URLRewriter.dll,下载之后直接复制到你的网站的bin目录中? 2.配置你的web.config文件? 在configuration节点下加? configSections? ? section name=RewriterConfig type=URLRewriter.Config.RewriterConfigSerializerSectionHandler, URLRewriter /? ? /configSections? RewriterConfig? ? Rules? ? !--一下三个是我自己写的测试的,当然你可以写很多个 --? ? !--这个是把http://localhost:2001/default.aspx?id=1 生成http://localhost:2001/d1.aspx 这种页面 --? ? RewriterRule? ? LookFor~/d(\d{0,5})\.aspx/LookFor? ? SendTo~/default.aspx?ID=$1/SendTo? ? /RewriterRule? ? !--这个是把http://localhost:2001/article.aspx?id=1 生成http://localhost:2001/1/a.html 这种页面 --? ? RewriterRule? ? LookFor~/(\d{0,5})/a\.html/LookFor? ? SendTo~/article.aspx?id=$1/SendTo? ? /RewriterRule? ? !--这个是把http://localhost:2001/test.aspx?id=1 生成http://localhost:2001/1/ 这种页面 --? ? RewriterRule? ? LookFor~/(\d{0,5})//LookFor? ? SendTo~/test.aspx?id=$1/SendTo? ? /R
原创力文档

文档评论(0)