/ 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.
Expand |
Embed | Plain Text
<% ' Copyright (c) 2008, reusablecode.blogspot.com; some rights reserved. ' ' This work is licensed under the Creative Commons Attribution License. To view ' a copy of this license, visit http://creativecommons.org/licenses/by/3.0/ or ' send a letter to Creative Commons, 559 Nathan Abbott Way, Stanford, California ' 94305, USA. ' Force communication using Secure Socket Layer. sub forceSSL() dim secureURL if UCase(Request.ServerVariables("HTTPS")) = "OFF" then secureURL = "https://" & Request.ServerVariables("SERVER_NAME") & Request.ServerVariables("HTTP_URL") if Request.ServerVariables("QUERY_STRING") <> "" then secureURL = secureURL & "?" & Request.ServerVariables("QUERY_STRING") end if Response.Redirect secureURL end if end sub %>
You need to login to post a comment.
