Why does Request.IsSecureConnection return false when true is expected Why does Request.IsSecureConnection return false when true is expected asp.net asp.net

Why does Request.IsSecureConnection return false when true is expected


If there's a load balancing router or similar in front of your web server with ssl termination then the connection from there to your web server won't be over SSL. In this case you usually have to check for a connection on a specific port or for headers being set by the load balancer.


Some load balancers add a new header to the request which you can use to determine if the original request from client came over SSL. With Azure websites the following code seems to work:

if (string.IsNullOrEmpty(Request.Headers["x-arr-ssl"])){     // No SSL}else{     // Secure connection}

Some other load balancers may use another header, for example X-Forwarded-Proto.