0

I have a load balanced webserver environment using a NetScaler load-balancer which is configured to add the header HTTP_X_FORWARDED_PROTO. This is either http / https depending on the request. I know that this header is coming through correctly.

I have created a rewrite rule in IIS 8.5 to set the SERVER_PORT and HTTPS server variables:

<rewrite>
                <allowedServerVariables>
                <add name="SERVER_PORT" />
                <add name="HTTPS" />
            </allowedServerVariables>
     <globalRules>
            <rule name="HTTPs Redirect">
                <match url="(.*)" />
                <conditions>
                    <add input="{ALL_HTTP}" matchType="Pattern" 
                         pattern="HTTP_X_FORWARDED_PROTO:https" ignoreCase="true" />
                </conditions>
                                    <serverVariables>
                       <set name="SERVER_PORT" value="443" />
            <set name="HTTPS" value="on" />
                    </serverVariables>
                    <action type="Redirect" url="https://{HTTP_HOST}/{R:1}" />

            </rule>
          </globalRules>

        </rewrite>

However the headers do not appear to change? I know the rule is working because I added an action to redirect to google.com and could see that working. I have a page that displays all the server varibles with this code:

<%

foreach (string var in Request.ServerVariables)
{
  Response.Write(var + " " + Request[var] + "<br />");
}

%>

I am really banging my head against the wall on this one, I have searched and searched online and can't see why it is not working?

Thanks

Luke

Luke Wilkinson
  • 439
  • 8
  • 17

1 Answers1

0

This can be fixed by adding the rule in the IIS user-interface rather than direct in the web.config. After adding the allowed server variables in IIS and re-creating the rule in IIS is started to work. I don't know where it adds the allowed server variables but they are no longer in the web.config and it is working.

Luke Wilkinson
  • 439
  • 8
  • 17
  • They go into applicationHost.config, which is located in C:\Windows\System32\inetsrv\config.see http://stackoverflow.com/questions/8635884/iis7-settings-file-locations – Henry Troup Jan 31 '16 at 04:19