我有一些IIS重写规则,我想根据环境变化。开发重写规则在web.config文件中,然后在web.test.config文件的末尾我有:
<appSettings> ...some app settings tranforms here </appSettings> <system.webserver> <rewrite xdt:Transform="Replace"> <rules> ... rules here </rules> </rewrite> </system.webserver> </configuration>
当我部署到测试时,我的应用程序设置正在变化,但是IIS重写规则不是。我希望整个< rewrite>部分将被替换为变换文件中的一个(根据http://msdn.microsoft.com/en-us/library/dd465326.aspx),但没有任何变化。
我试过把xdt:Transform =“替换”xdt:Locator =“匹配(名称)”>对个别规则:
<rule name="Test rule" stopProcessing="true" xdt:Transform="Replace" xdt:Locator="Match(name)">
但同样这没有什么区别。
甚至可以替换web.config中的重写规则,如果是这样,我缺少什么?
解决方法
因为我没有在我的主web.config中的任何重写规则,替换转换不工作。我成功地使用了Insert转换,如下:
<system.webServer> <rewrite xdt:Transform="Insert"> <rules> <rule name="CanonicalHostNameRule1"> <match url="(.*)" /> <conditions> <add input="{HTTP_HOST}" pattern="^www\.mysite\.com$" negate="true" /> </conditions> <action type="Redirect" url="http://www.mysite.com/{R:1}" /> </rule> </rules> </rewrite> </system.webServer>
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。