之前使用URLRewrite在IIS6中一切正常,但是在IIS7却不能正常使用,提示“无法找到资源”,这时需要在web.config中system.webServer节点中的handlers节点进行配置,如下:
IIS6中的配置:
![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif)
Code
1 <configuration>
2 ![](https://www.cnblogs.com/Images/dot.gif)
3 <configSections>
4 <section name="RewriterConfig" type="URLRewriter.Config.RewriterConfigSerializerSectionHandler, URLRewriter"/>
5 </configSections>
6 <RewriterConfig>
7 <Rules>
8 <RewriterRule>
9 <LookFor>~/Index\.aspx</LookFor>
10 <SendTo>~/Content/Index.aspx</SendTo>
11 </RewriterRule>
12 </Rules>
13 </RewriterConfig>
14
15 <system.web>
16 <httpHandlers>
17 <add verb="*" path="*.aspx" type="URLRewriter.RewriterFactoryHandler, URLRewriter"/>
18 </httpHandlers>
19 </system.web>
20 ![](https://www.cnblogs.com/Images/dot.gif)
21 </configuration>
如果在IIS7中使用,需在web.config中加入:
![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif)
Code
1 <configuration>
2 ![](https://www.cnblogs.com/Images/dot.gif)
3 <system.webServer>
4 <validation validateIntegratedModeConfiguration="false"/>
5 <modules>
6 <add type="URLRewriter.ModuleRewriter, URLRewriter" name="ModuleRewriter" />
7 </modules>
8 <system.webServer>
9 ![](https://www.cnblogs.com/Images/dot.gif)
10 </configuration>
加入以上代码后,URLRewrite就可以同时在IIS6和IIS7中正常使用了。
--EricZhang
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步