强制使用 SSL,但 web.config 中有例外

Force SSL with exceptions in web.config

我目前在 web.config 中有以下内容来强制使用 SSL,但是我需要排除特定路径被强制使用。

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <rewrite>
            <rules>
                <rule name="Redirect to HTTPS From HTTP" stopProcessing="true">
                    <match url="(.*)" />
                    <conditions>
                        <add input="{HTTPS}" pattern="^OFF$" />
                    </conditions>
                    <action type="Redirect" url="https://{HTTP_HOST}/{R:1}" redirectType="SeeOther" />
                </rule>
            </rules>
        </rewrite>
    </system.webServer>
</configuration>

我尝试更改 match url 以反转特定路径,但它似乎没有被捕获。

示例:

site.com/app/default.aspx - 强制 SSL site.com/app/service/cashback.svc - 非强制,仅限 HTTP site.com/app/service/different.svc - 强制 SSL(所以它不是必须排除的完整目录)

您可以将例外情况添加到 <conditions>,例如

<add input="{REQUEST_URI}" matchType="Pattern" negate="true" pattern="/app/service/cashback\.svc" />