您好我想为"重定向到HTTPS"重新插入重写规则。但仅限于我的发布配置
这是重写规则的外观
<system.webServer>
<rewrite>
<rules>
<rule name="Redirect to HTTPS">
<match url="(.*)" />
<conditions>
<add input="{HTTPS}" pattern="off" ignoreCase="true" />
<add input="{URL}" pattern="/$" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
</conditions>
<action type="Redirect" url="https://{SERVER_NAME}/{R:1}" redirectType="SeeOther" />
</rule>
</rules>
</rewrite>
</system.webServer>
如何仅在我的release.config中实现此目的?
答案 0 :(得分:5)
只需在需要插入web.config发行版的元素上添加xdt:Transform="Insert"
属性。例如,如果您的初始web.config根本不包含<rewrite>
元素,则release.config应如下所示:
<system.webServer>
<rewrite xdt:Transform="Insert">
<rules>
<rule name="Redirect to HTTPS">
<match url="(.*)" />
<conditions>
<add input="{HTTPS}" pattern="off" ignoreCase="true" />
<add input="{URL}" pattern="/$" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
</conditions>
<action type="Redirect" url="https://{SERVER_NAME}/{R:1}" redirectType="SeeOther" />
</rule>
</rules>
</rewrite>
</system.webServer>
否则,如果初始web.config已包含其他一些规则,那么您只需要在xdt:Transform="Insert"
元素级别添加<rule>
属性:
<system.webServer>
<rewrite>
<rules>
<rule name="Redirect to HTTPS" xdt:Transform="Insert">
<match url="(.*)" />
<conditions>
<add input="{HTTPS}" pattern="off" ignoreCase="true" />
<add input="{URL}" pattern="/$" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
</conditions>
<action type="Redirect" url="https://{SERVER_NAME}/{R:1}" redirectType="SeeOther" />
</rule>
</rules>
</rewrite>
</system.webServer>
答案 1 :(得分:0)
您可以查看web.config转换: https://msdn.microsoft.com/library/dd465318(v=vs.100).aspx
创建和编码转换文件