http到https重写了太多重定向循环IIS 7

Pra*_*ite 15 asp.net iis asp.net-mvc loops url-rewriting

我有我在IIS 7.0中托管的应用程序.我必须确保它只在HTTPS上工作而不在HTTP上工作,所以我在root配置中包含了以下规则.

<rewrite>
        <rules>
            <rule name="HTTP to HTTPS redirect" stopProcessing="true">
              <match url="(.*)" />
              <conditions>
                <add input="{HTTPS}" pattern="off" />
              </conditions>
              <action type="Redirect" url="https://{HTTP_HOST}{REQUEST_URI}"   redirectType="Found" />
            </rule>
        </rules>
</rewrite> 
Run Code Online (Sandbox Code Playgroud)

当我尝试访问我的应用程序时添加此规则后,我得到以下错误:

页面导致了太多的重定向.清除此站点的cookie或允许第三方cookie可以解决问题.如果没有,它可能是服务器配置问题,而不是您的计算机的问题.以下是一些建议:稍后重新加载此网页.详细了解此问题.

Gpa*_*mar 19

放在输入条件下面:

<add input="{HTTPS}" pattern="on" /> 
Run Code Online (Sandbox Code Playgroud)

代替:

<add input="{HTTPS}" pattern="off" />
Run Code Online (Sandbox Code Playgroud)


SNa*_*Nag 12

我们使用Elastic Load Balancing在AWS上托管我们的ASP.NET应用程序,问题中带有已接受答案的规则对我们不起作用,并继续导致无限重定向.

这是最终为我们工作的规则:

<rewrite>
   <rules>
      <rule name="HTTPS Rule behind AWS Elastic Load Balancer Rule" stopProcessing="true">
         <match url="^(.*)$" ignoreCase="false" />
         <conditions>
            <add input="{HTTP_X_FORWARDED_PROTO}" pattern="^http$" ignoreCase="false" />
         </conditions>
         <action type="Redirect" url="https://{SERVER_NAME}{URL}" redirectType="Found" />
      </rule>
   </rules>
</rewrite>
Run Code Online (Sandbox Code Playgroud)

  • 有人给这个人一个OSCAR!您刚刚救了我的命,还给了我理智!!谢谢!!上帝祝福你!! (2认同)