Switching Between HTTP and HTTPS

Discussion in 'ASP General' started by Kenneth Keeley, Oct 14, 2003.

  1. Hi
    I wish to have a web site that has most of the pages as normal HTTP pages
    but has some areas that use HTTPS. I want to have it that if a user selects
    a link to a HTTPS page that they go there an there Session Information is
    kept. I also wish to have the pages switch automatically to HTTPS if a
    visitor types the URL without the HTTPS. So my questions are:
    1) How to redirect to a Secure Page without losing Session Info?
    2) How to test if page is accessed by HTTPS, and if not switch to HTTPS
    quickly?

    I think something like this code is what I want but how do I do it.

    <%
    if not "HTTPS" then
    response.redirect(https://mysite.com/securepage.asp)
    end if
    %>

    Thanks for the help.
    Kenneth Keeley
     
    Kenneth Keeley, Oct 14, 2003
    #1
    1. Advertising

  2. Kenneth Keeley

    Ray at Guest

    "Kenneth Keeley" <> wrote in message
    news:...
    > So my questions are:
    > 1) How to redirect to a Secure Page without losing Session Info?


    This is not possible. Sessions cannot be maintained across different
    protocols. You'll have to store the info server-side in a database, for
    example.

    > 2) How to test if page is accessed by HTTPS, and if not switch to

    HTTPS
    > quickly?


    Here's an example:
    http://www.aspfaq.com/2321

    You'd probably also want to grab the querystring, should it exist. Maybe do
    it like this instead (illustrative example):

    <%
    Dim sRedirect, sDomain, sPath, sQString
    If UCase(Request.ServerVariables("HTTPS") = "OFF" Then
    sDomain = Request.ServerVariables("SERVER_NAME")
    sPath = Request.ServerVariables("SCRIPT_NAME")
    sQString = Request.Querystring
    sRedirect = "https://" & sDomain & sPath
    If Len(sQString) > 0 Then sRedirect = sRedirect & "?" & sQString
    Response.Redirect sRedirect
    End If
    %>


    Ray at home
     
    Ray at, Oct 14, 2003
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jerry III

    Re: Switching Between HTTP and HTTPS

    Jerry III, Oct 15, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    952
    Jerry III
    Oct 15, 2003
  2. Hemant

    switching between https and http

    Hemant, Sep 16, 2009, in forum: ASP .Net
    Replies:
    0
    Views:
    301
    Hemant
    Sep 16, 2009
  3. Tony Wright

    Switching between http and https popping up a login box

    Tony Wright, May 28, 2004, in forum: ASP .Net Security
    Replies:
    0
    Views:
    135
    Tony Wright
    May 28, 2004
  4. CS

    Switching between http and https

    CS, Apr 29, 2005, in forum: ASP .Net Security
    Replies:
    1
    Views:
    167
    Jason Brown [MSFT]
    Apr 29, 2005
  5. Mike Tallman
    Replies:
    0
    Views:
    123
    Mike Tallman
    Nov 22, 2005
Loading...

Share This Page