Switching Between HTTP and HTTPS Automatically

Put this code in the beginning  of ASP Page

Response.Buffer = True
If (Request.ServerVariables("HTTPS") = "off") Then

   Dim xredir__, xqstr__
    xredir__ = "https://" & Request.ServerVariables("SERVER_NAME") & _
               Request.ServerVariables("SCRIPT_NAME")
    xqstr__ = Request.ServerVariables("QUERY_STRING")
    if xqstr__ <> "" Then xredir__ = xredir__ & "?" & xqstr__
    Response.redirect xredir__

End if