http 重定向到 https

最近遇到如下问题,网站安全扫描时检测到的漏掉。

服务器环境: Windows 2008 R2 + IIS 7.5   

网站:ASP.NET

修改了web config 中的设置

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

参考:https://www.hadsky.com/read-3212-1.html

https://blog.csdn.net/jackbon8/article/details/84578904 (这里有Apache环境、Ngnix环境的设置方法, 但我没有使用到,有需要的可做参考)

原文地址:https://www.cnblogs.com/catherinehu/p/15218361.html