Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/security/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net 在Azure WebRoles中启用HTTP严格传输安全性(HSTS)_Asp.net_Security_Iis_Azure - Fatal编程技术网

Asp.net 在Azure WebRoles中启用HTTP严格传输安全性(HSTS)

Asp.net 在Azure WebRoles中启用HTTP严格传输安全性(HSTS),asp.net,security,iis,azure,Asp.net,Security,Iis,Azure,如何为Azure WebRoles启用HTTP严格传输安全性(HSTS)?有一个IIS模块,该模块支持HSTS符合HSTS草案规范(RFC 6797);你可以在这里找到它 不要尝试以下操作: <system.webServer> <httpProtocol> <customHeaders> <add name="Strict-Transport-Security" value="max-age=315360

如何为Azure WebRoles启用HTTP严格传输安全性(HSTS)?

有一个IIS模块,该模块支持HSTS符合HSTS草案规范(RFC 6797);你可以在这里找到它

不要尝试以下操作:

<system.webServer>
    <httpProtocol>
        <customHeaders>
            <add name="Strict-Transport-Security" value="max-age=31536000; includeSubDomains"/>
        </customHeaders>
    </httpProtocol>
</system.webServer>


因为这将包括通过非安全传输的HTTP响应中的STS头。

接受的答案令人困惑,并且(在服务器上的错误)隐藏在注释中,因此我将在这里快速重述它。基本上这就是你想要做的:

  • 将所有HTTP请求重定向到HTTPS
  • 严格传输安全性
    头添加到所有HTTPS请求中
  • 相应的web.config如下所示:

    <?xml version="1.0" encoding="UTF-8"?>
    <configuration>
        <system.webServer>
            <rewrite>
                <rules>
                    <rule name="HTTP to HTTPS redirect" stopProcessing="true">
                        <match url="(.*)" />
                        <conditions>
                            <add input="{HTTPS}" pattern="off" ignoreCase="true" />
                        </conditions>
                        <action type="Redirect" url="https://{HTTP_HOST}/{R:1}"
                            redirectType="Permanent" />
                    </rule>
                </rules>
                <outboundRules>
                    <rule name="Add Strict-Transport-Security when HTTPS" enabled="true">
                        <match serverVariable="RESPONSE_Strict_Transport_Security"
                            pattern=".*" />
                        <conditions>
                            <add input="{HTTPS}" pattern="on" ignoreCase="true" />
                        </conditions>
                        <action type="Rewrite" value="max-age=31536000" />
                    </rule>
                </outboundRules>
            </rewrite>
        </system.webServer>
    </configuration>
    

    当然,将
    yourdomain
    与您的实际域切换。

    您的项目是什么?MVC?Web表单?看看我最近写的文章可能会对您的目标有所帮助。此解决方案与HSTS规范冲突。查看第7.2节,您是否正在寻找一个重定向过滤器,该过滤器为非安全请求发送301?如果您包含了这些细节,也许会更容易得到答案,而不是让人们去注册:那么,您如何安装它呢?我可以在Azure中安装HSTS-IIS-Module-2.0.0.msi文件吗?还是我将DLL复制到我的ASP.NET MVC 5应用程序的BIN文件夹中?考虑添加<代码>包括Ubjase @ yyt看起来好像你走运了:<代码>重定向类型< /代码>指定重定向期间要使用的状态代码:301 -永久的、302查找的、303的-查看其他的、307个临时的()。这就是我所担心的。谢谢你的确认。我想我可能需要在我的应用程序中使用自定义asp.net过滤器。不好意思,我喜欢这个解决方案。很棒的解决方案。我在Azure应用程序服务上使用它,它工作正常。@Jake不一定,该规则只会将以
    mysite.com
    开头的任何内容重定向到
    www.mysite.com
    。因此,
    shop.mysite.com
    (或任何其他子域)不会受到影响。
    <rewrite>
      <rules>
        <rule name="Redirect to HTTPS" stopProcessing="true">
          <match url="(.*)" />
          <conditions logicalGrouping="MatchAll">
            <add input="{SERVER_NAME}" pattern="^localhost$" negate="true" />
            <add input="{HTTPS}" pattern="off" ignoreCase="true" />
          </conditions>
          <action type="Redirect" url="https://{HTTP_HOST}/{R:1}" redirectType="Permanent" />
        </rule>
        <rule name="Redirect to www" stopProcessing="true">
          <match url="(.*)" />
          <conditions>
            <add input="{HTTP_HOST}" pattern="^yourdomain\.com" ignoreCase="true" />
          </conditions>
          <action type="Redirect" url="https://www.yourdomain.com/{R:1}" 
               redirectType="Permanent" />
        </rule>
      </rules>
      <outboundRules>
        <rule name="HSTS" enabled="true">
          <match serverVariable="RESPONSE_Strict_Transport_Security" pattern=".*" />
          <conditions>
            <add input="{HTTPS}" pattern="on" ignoreCase="true" />
          </conditions>
          <action type="Rewrite" value="max-age=31536000; includeSubDomains; preload" />
        </rule>
      </outboundRules>
    </rewrite>