When you think ASP, think...
Recent Articles
All Articles
ASP.NET Articles [1.x] [2.0]
ASPFAQs.com
Message Board
Related Web Technologies
User Tips!
Coding Tips
Search

Sections:
Book Reviews
Sample Chapters
Commonly Asked Message Board Questions
Headlines from ASPWire.com
JavaScript Tutorials
MSDN Communities Hub
Official Docs
Security
Stump the SQL Guru!
Web Hosts
XML Info
Information:
Advertise
Feedback
Author an Article
Technology Jobs



















internet.com
IT
Developer
Internet News
Small Business
Personal Technology

Search internet.com
Advertise
Corporate Info
Newsletters
Tech Jobs
E-mail Offers
ASP ASP.NET ASP FAQs Message Board Feedback ASP Jobs
Print this page.

Business Systems Analyst - Clearing - SQL Server - ASP - VB (IL)
Next Step Systems
US-IL-Chicago

Justtechjobs.com Post A Job | Post A Resume

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!

Return to user tips...


Windows Internet Technology | ASP.NET [1.x] [2.0] | ASPMessageboard.com | ASPFAQs.com | Advertise | Feedback | Author an Article


The Network for Technology Professionals

Search:

About Internet.com

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | E-mail Offers