Redirect HTTP traffic to HTTPS with IIS


There are many situations where you’d want a site to be accessible only securely, and there are several resources online on how to accomplish this. Unfortunately, I couldn’t find a perfect solution for me. Influenced by this info and following the steps outlined here (under In Windows Server 2003 (IIS 6.0)), I came up with the following:

CODE:
<%
If Request.ServerVariables(“SERVER_PORT”)=80 Then
Dim strSecureURL

strSecureURL = Replace(Request.QueryString,”http”,”https”) ‘ entire old URL, but w/https
strSecureURL = Replace(strSecureURL,”403;”,”") ‘ remove “403;” from beginning
strSecureURL = Replace(strSecureURL,”:80″,”") ‘ remove port # that’s appended to server name
Response.Redirect strSecureURL
End If
%>

It works well for my purposes, but of course, your mileage may vary.

More resources:

1. http://support.microsoft.com/kb/239875
2. http://support.microsoft.com/kb/839357
3. http://blog.opsan.com/archive/2005/04/17/395.aspx







Posted in Tech Corner

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">