我有一个ASP.NET Webforms应用程序,它正在使用NWebsec。它按预期工作,但我试图从一开始就强制HTTPS,而不是在使用HSTS进行初始请求之后。当我添加URL重写时,它会在一个重定向循环中得到。删除NWebsec和URL重写很好。NWebsec在这两种情况下都可以工作,但是如果没有重写,如果它们加载了HTTP,它就不会强制HTTPS。upgrade-insecure-requests本身不起作用。
URL重写规则
<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>NWebsec Config
<nwebsec>
<httpHeaderSecurityModule xmlns="http://nwebsec.com/HttpHeaderSecurityModuleConfig.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="NWebsecConfig/HttpHeaderSecurityModuleConfig.xsd">
<redirectValidation enabled="true" />
<setNoCacheHttpHeaders enabled="true" />
<x-Robots-Tag enabled="false" noIndex="false" noFollow="false" noArchive="false" noOdp="false" noSnippet="false" noImageIndex="false" noTranslate="false" />
<securityHttpHeaders>
<x-Frame-Options policy="Deny" />
<strict-Transport-Security max-age="60" includeSubdomains="true" httpsOnly="true" preload="false" />
<x-Content-Type-Options enabled="true" />
<x-Download-Options enabled="false" />
<x-XSS-Protection policy="Disabled" blockMode="true" />
<content-Security-Policy enabled="true">
<upgrade-insecure-requests enabled="true" />
</content-Security-Policy>
</securityHttpHeaders>
</httpHeaderSecurityModule>
</nwebsec>发布于 2016-08-05 02:10:22
发现了问题,PEBKAC。应该更好地阅读文档。
<redirectValidation enabled="true">
<allowSameHostRedirectsToHttps enabled="true" />
</redirectValidation>https://stackoverflow.com/questions/38779498
复制相似问题