Posted By

Scooter on 05/19/08


Tagged

ssl


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

wizard04
nelda751


Force SSL


 / Published in: ASP
 

URL: http://reusablecode.blogspot.com/2008/04/force-ssl.html

There are some things here worth noting. We are checking if HTTPS is off. Some people will instead check if traffic is coming from port 80, the standard HTTP port, or not coming from 443, the standard HTTPS port. Checking port numbers is not the best solution because the server administrator can set up HTTP and HTTPS to run on different ports. It's also worth noting that QueryString variables are preserved, if any are being passed. Most other examples I've seen on the Internet ignore the QueryString variables, which leads to navigation problems.

  1. <%
  2. ' Copyright (c) 2008, reusablecode.blogspot.com; some rights reserved.
  3. '
  4. ' This work is licensed under the Creative Commons Attribution License. To view
  5. ' a copy of this license, visit http://creativecommons.org/licenses/by/3.0/ or
  6. ' send a letter to Creative Commons, 559 Nathan Abbott Way, Stanford, California
  7. ' 94305, USA.
  8.  
  9. ' Force communication using Secure Socket Layer.
  10. sub forceSSL()
  11. dim secureURL
  12.  
  13. if UCase(Request.ServerVariables("HTTPS")) = "OFF" then
  14. secureURL = "https://" & Request.ServerVariables("SERVER_NAME") & Request.ServerVariables("HTTP_URL")
  15.  
  16. if Request.ServerVariables("QUERY_STRING") <> "" then
  17. secureURL = secureURL & "?" & Request.ServerVariables("QUERY_STRING")
  18. end if
  19.  
  20. Response.Redirect secureURL
  21. end if
  22. end sub
  23. %>

Report this snippet  

You need to login to post a comment.