DrG*_*feN 1 asp.net xslt web-config-transform xdt-transform
嗨,我想为“重定向到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>
Run Code Online (Sandbox Code Playgroud)
如何仅在我的release.config中实现此目的?
只需xdt:Transform="Insert"在需要插入到web.config的发行版中的元素上添加属性。例如,如果您最初的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>
Run Code Online (Sandbox Code Playgroud)
否则,如果初始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>
Run Code Online (Sandbox Code Playgroud)
小智 0
您可以查看 web.config 转换: https://msdn.microsoft.com/library/dd465318(v=vs.100 ).aspx
创建转换文件并对其进行编码
| 归档时间: |
|
| 查看次数: |
2625 次 |
| 最近记录: |