Redirect HTTP traffic to HTTPS with IIS

22 03 2009

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









Trackbacks


No Trackbacks

Comments

Display comments as (Linear | Threaded)
No comments

Add Comment


You can use [geshi lang=lang_name [,ln={y|n}]][/geshi] tags to embed source code snippets.
Enclosing asterisks marks text as bold (*word*), underscore are made via _word_.
Standard emoticons like :-) and ;-) are converted to images.
BBCode format allowed

To prevent automated Bots from commentspamming, please enter the string you see in the image below in the appropriate input box. Your comment will only be submitted if the strings match. Please ensure that your browser supports and accepts cookies, or your comment cannot be verified correctly.
CAPTCHA