473,587 Members | 2,230 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

HTTP to HTTPS redirect resulting in a loop

1 New Member
Just before I go an tell my sys admin that the server has problems I wanted to run this by everyone on here. Basically we have a few pages that need to be sent over https. Everything I have found on the internet resulted in this code

Expand|Select|Wrap|Line Numbers
  1. If (Request.ServerVariables("HTTPS") = "off") Then
  2.         srvname = Request.ServerVariables("SERVER_NAME")
  3.         scrname = Request.ServerVariables("SCRIPT_NAME")
  4.         Response.Redirect("https://" & srvname & scrname)
  5.     End If
I will say that this code has worked for me over a month and then all of the sudden it stops working and always gives a redirect loop error. I have already checked that the ServerVariables is "off" during an http request and it is "on" during an https request.

Honestly, this code should work and it has been working until recently. Unfortunately my sysadmin believes it is faulty code and told me to rewrite it, claiming that his server could "have no faults."

Anyone have an idea or should this code work? btw it is being run on IIS 6
Jan 19 '09 #1
1 4112
Nicodemas
164 Recognized Expert New Member
Just a thought, but are you sure you are correctly comparing strings? I use this, which returns a numeric value so I don't have to worry about uppercase and lowercase comparison differences:

Expand|Select|Wrap|Line Numbers
  1. i = Request.ServerVariables("SERVER_PORT_SECURE")
  2. '// returns 1 or 0
  3.  
You could still use yours, but ensure the case of the result is what you expect:

Expand|Select|Wrap|Line Numbers
  1. If (lcase(Request.ServerVariables("HTTPS")) = "off") Then 
  2.    srvname = Request.ServerVariables("SERVER_NAME") 
  3.    scrname = Request.ServerVariables("SCRIPT_NAME") 
  4.    Response.Redirect("https://" & srvname & scrname)
  5. End If 
  6.  
Jan 20 '09 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

5
89872
by: Bob Hansen | last post by:
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"))
1
2183
by: dave | last post by:
Hello I have one simple form (myform.asp) and it posts to query.asp I had put below code in both file on top of the page to redirect this two pages in https:// so any one can access it thru http , it changes to https:// if Request.ServerVariables("HTTPS") = "off" then method = Request.ServerVariables("REQUEST_METHOD") srvname =...
2
3491
by: McKirahan | last post by:
I have an ASP site, an SSL certificate, and an {Order page}. I want to use "https" for the {Order page} and "http" for all others. Each page "includes" a common ".asp" file which detects the current protocol and page via the Request.ServerVariables(): "SERVER_PORT_SECURE" and "SCRIPT_NAME", respectively. ( If "SERVER_PORT_SECURE" = 1...
3
1692
by: Raymond Tam | last post by:
When I am using server-side button to switch from https to http by using response.redirect "http://a.apsx" in response to the client event, I am still at the https environment (ie. the address bar on the IE is https://a.aspx). However, when using hyperlink control, there is no mis-representation. Can anyone advise how to deal with this? ...
5
3608
by: Dabbler | last post by:
I'm sending users to a secure page https to fill out a registration form. When they're done I show a thank you page. I need to return the user to http mode after filling out the form. If I use response.redirect I get a security warning when transitioning from https to http. Is there an accepted way to avoid having the user see this? ...
14
3044
by: david | last post by:
I have developed web forms including login by using ASP.NET via HTTP. Now I want to secure the connection from client to the server via HTTPS. How can I configure the server or something else to make the change? Thank you David
7
13438
by: =?Utf-8?B?YzY3NjIyOA==?= | last post by:
Hi all, I am trying to set this up using asp code and IIS configuration. But it seems not working. Here it is the way I am doing. In IIS I set up a virtual directory with secure communication, I checked require secure channel, require 128-bit encryption. In custom error, instead of using default message HTTP 403.4 - Forbidden: SSL required...
8
5133
by: howa | last post by:
a page currently in HTTPS, I force the client to redirect to another page using HTTP under the same domain (e.g. abc.com), i.e. header("Location: http://www.abc.com/index.php"); IE successfully redirect to HTTP, but FF & Opera stay on the HTTPS any suggestions?
0
4343
by: Raven | last post by:
Hi, I have a problem with a server side redirect from a secure page to a non-secure page (same domain name, same folder) I have added some test code that can display the target URL and that containt http:// and yet it redirects to https:// example: I am on
0
7915
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7843
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8205
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7967
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
1
5712
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3840
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
2347
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1452
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1185
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.