HTTP to HTTPS redirect behind Load Balancer on port 443
I have a load balancer listening on both ports 80 and 443, but due to a security policy the traffic between the load balancer and the web servers must be encrypted. I'm trying to produce a redirect from http to https, but the usual methods aren't working, presumeably because IIS can't tell the difference between the originating requests on http vs https. This is because by the time the request gets to the web server it is already encrypted and coming down port 443.

Right now I'm using the rewrite module with mods to web.config, and the redirect works fine for 80->LB->80 traffic, but not for 80->LB->443 traffic.

Here's my 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" redirectType="Found" url="https://{HTTP_HOST}/{R:1}" />
            </rule>
            </rules>
            </rewrite>
        </system.webServer>
        </configuration>

Note, something I like about the web.config solution (if it can be modified to work for 80->LB->443) is that the redirect works for non ASP.NET pages too.

Any ideas?

HTTP to HTTPS redirect behind Load Balancer on port 443
===

I have a load balancer listening on both ports 80 and 443, but due to a security policy the traffic between the load balancer and the web servers must be encrypted. I'm trying to produce a redirect from http to https, but the usual methods aren't working, presumeably because IIS can't tell the difference between the originating requests on http vs https. This is because by the time the request gets to the web server it is already encrypted and coming down port 443.

Right now I'm using the rewrite module with mods to web.config, and the redirect works fine for 80->LB->80 traffic, but not for 80->LB->443 traffic.

Here's my 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" redirectType="Found" url="https://{HTTP_HOST}/{R:1}" />
            </rule>
            </rules>
            </rewrite>
        </system.webServer>
        </configuration>

Note, something I like about the web.config solution (if it can be modified to work for 80->LB->443) is that the redirect works for non ASP.NET pages too.

Any ideas?
