NWebsec和URL重写冲突

时间:2016-08-05 00:42:33

标签: asp.net url-rewriting webforms iis-7.5 nwebsec

我有一个ASP.NET Webforms应用程序,它正在使用NWebsec。它按预期工作,但我试图从一开始就强制使用HTTPS,而不是在使用HSTS初始请求之后。当我添加URL Rewrite时,它会进入重定向循环。删除NWebsec和URL重写工作正常。 NWebsec可以在任何一种情况下工作,但如果加载HTTP则不进行重写,它不会强制使用HTTPS。 upgrade-insecure-requests无法自行运行。

网址重写规则

<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配置

<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>

1 个答案:

答案 0 :(得分:0)

发现问题,PEBKAC。应该更好地阅读documentation

<redirectValidation enabled="true">
    <allowSameHostRedirectsToHttps enabled="true" />
</redirectValidation>