HTTP to HTTPS redirect

B

Bob Hansen

I am using the following code in my default.asp page to redirect the page
from HTTP to HTTPS

<%

if Request.ServerVariables("HTTPS") = "off" Then

Response.Redirect("https://" & Request.ServerVariables("HTTP_HOST") &
Request.ServerVariables("URL"))

End if
%>

I got the code off of a website and found that many web sites had similar
code for doing the same thing. The problem I am having is that the code
will not redirect to the HTTPS and will keep reloading the page. Is there a
setup issue with IIS that I might be missing?

Thanks

Bob Hansen
 
B

Bob Barrows

Bob said:
I am using the following code in my default.asp page to redirect the
page from HTTP to HTTPS

<%

if Request.ServerVariables("HTTPS") = "off" Then

Response.Redirect("https://" &
Request.ServerVariables("HTTP_HOST") & Request.ServerVariables("URL"))

End if
%>

I got the code off of a website and found that many web sites had
similar code for doing the same thing. The problem I am having is
that the code will not redirect to the HTTPS and will keep reloading
the page. Is there a setup issue with IIS that I might be missing?

Thanks

Bob Hansen

Have you verified that Request.ServerVariables("HTTPS") contains what you
think it contains? Response.Write it to be sure.

Bob Barrows
 
B

Bob Hansen

Bob Barrows said:
Have you verified that Request.ServerVariables("HTTPS") contains what you
think it contains? Response.Write it to be sure.

Bob Barrows
--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.
Value is set to "off" on the first pass, after that I cannot tell because it
keeps redirecting into a loop so I am pretty sure that the server variable
for HTTPS is never getting set to anything but "off"
 
B

Bob Hansen

That didnt work either. This solution just made it so all of the pages were
unauthorized for viewing.
 
M

Mark Schupp

Put a page containing the following in the same directory as your other
page.

Response.Write Request.ServerVariables("HTTPS")

call it using http: and see what it returns.
then call it using https

This might give you a clue.
 

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

Forum statistics

Threads
473,995
Messages
2,570,225
Members
46,815
Latest member
treekmostly22

Latest Threads

Top