Automatically toggle between https and http

F

Framework fan

Hi,

Is this possible:

Have a seperate folder that just contains the aspx webforms that you
require to run under SSL https. (Set IIS directory permissions up for
this folder to be used for SSL)

Then have a default webform page with a button on it with this code:

Response.Redirect("Special_SSL_Folder/SSLPage.aspx")

When you are redirected, the browser "automatically" uses httpS,
rather than http. (Based on the IIS directory permissions set up for
SSL on this folder.)

Then, on the SSL webform page, you have another button on it with this
code:

Response.Redirect("../Non_SSL_Folder/NormalPage.aspx") 'Go back to
http

When you are redirected, the browser "automatically" drops the secure
SSL https connection, and you are back to using http again. (Because
the webforms inside the Non_SSL_Folder doesn't have SSL https settings
set under IIS.)

Is this possible?

Many thanks for any information.

Best regards from Frameworker.
 
F

Framework fan

I have solved my problem.

For any aspx webform that you want to use for SSL, put this inside the
Page_Init function:

Response.Buffer = True
If (Request.ServerVariables("HTTPS") = "off") Then
Dim xredir__, xqstr__ As String

xredir__ = "https://" &
Request.ServerVariables("SERVER_NAME") & _

Response.ApplyAppPathModifier(Request.ServerVariables("SCRIPT_NAME"))
xqstr__ = Request.ServerVariables("QUERY_STRING")

If xqstr__ <> "" Then xredir__ = xredir__ & "?" & xqstr__

Response.Redirect(xredir__)
End If

Then, for all your other aspx webforms that don't require SSL, put
this inside the Page_Init function:

Response.Buffer = True
If (Request.ServerVariables("HTTPS") = "on") Then
Dim xredir__, xqstr__ As String

xredir__ = "http://" &
Request.ServerVariables("SERVER_NAME") & _

Response.ApplyAppPathModifier(Request.ServerVariables("SCRIPT_NAME"))
xqstr__ = Request.ServerVariables("QUERY_STRING")

If xqstr__ <> "" Then xredir__ = xredir__ & "?" & xqstr__

Response.Redirect(xredir__)
End If

Please notice the use of the ApplyAppPathModifier method. This is
used in order to preserve session state if you are using the
cookieless option.

Most of the code above was taken from the 4guysfromrolla site. I just
put the code inside the code behind section, rather than using <% %>
inside html. Also, I noticed the use of the ApplyAppPathModifier
method inside another thread in the .net newsgroups, and I needed it
because I use cookieless state.

-Frameworker.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,734
Messages
2,569,441
Members
44,832
Latest member
GlennSmall

Latest Threads

Top