User Tips: Quickly Switching Between HTTP and HTTPS
By David P.
I would like to post the following tip which I use for eCommerce sites that
use HTTPS.
It is often necessary to jump in and out of HTTPS by using Response.Redirect
(or sometimes by using a relative link). I have therefore had to write some
code either to force HTTPS for those pages that need it and inversely force
HTTP when being redirected from a HTTPS page (since HTTPS really slows things
down).
To force an ASP page to load with the HTTPS protocl, include the following code
fragment at the top of the 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
%>
|
The inverse function - forcing a page to load using the HTTP protocol - can be seen below:
<%
Response.Buffer = True
If (Request.ServerVariables("HTTPS") = "on") Then
Dim xredir__, xqstr__
xredir__ = "http://" & Request.ServerVariables("SERVER_NAME") & _
Request.ServerVariables("SCRIPT_NAME")
xqstr__ = Request.ServerVariables("QUERY_STRING")
if xqstr__ <> "" Then xredir__ = xredir__ & "?" & xqstr__
Response.redirect xredir__
End if
%>
|
Happy Programming!