473,714 Members | 2,530 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 4127
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
89920
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
2192
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 = Request.ServerVariables("SERVER_NAME") scrname = Request.ServerVariables("SCRIPT_NAME") sRedirect = "https://"...
2
3497
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 Then "https" else http". )
3
1767
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? Is it .NET bug?
5
3621
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? Thanks.
14
3053
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
13449
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 Internet Information Services in iishelp 403.4htm, I am trying to do redirect automatically. so I...
8
5142
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
4349
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
9314
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. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9175
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9075
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 most users, this new feature is actually very convenient. If you want to control the update process,...
0
9017
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6634
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5948
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4464
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3158
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
3
2111
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.