Click here to Skip to main content
15,887,135 members
Please Sign up or sign in to vote.
5.00/5 (2 votes)
See more:
The
C#
Request.ServerVariables("HTTP_REFERER")
is not working in the Internet Explorer.

We have a requirement like, there are two different websites say, www.example1.com and www.example2.com. I have to redirect all the users who uses www.example1.com to www.example2.com, and when we intentionally select www.example1.com in the dropdown list of www.example2.com it should have to open without any redirection.

For this I have used
C#
Request.ServerVariables("HTTP_REFERER") 
in the www.example1.com so that I can Identify who are requesting www.example1.com based on that I applied redirection. This worked great in All standard browsers like Mozilla and Google Chrome but not applying for Internet Explorer.

I used the below ASP code for www.example1.com

C#
<%if(Request.ServerVariables("HTTP_REFERER") <> "http://www.example2.org/") then

  URL = "http://api.ipinfodb.com/v3/ip-country/?key=c184c2d089c7763a81d7701a662b57fe3bf90dbfd8bf60d29948878531e24472&ip=" &           Request.ServerVariables("REMOTE_ADDR")
                  Set conn = Server.CreateObject("MSXML2.ServerXMLHTTP")
              conn.open "GET", URL, False, "", ""
              conn.send
                  UserCountry = conn.ResponseText
                  conArray = Split(UserCountry, ";")
              if ((conArray(3) = "US")) Then
                  response.redirect("http://www.example2.org/")
              end if
  end if
   %>


It worked fine in all Browsers except IE. Can any one know regarding this? would you please suggest me the equivalent code for ALL BROWSERS (Including IE) which would give similar results as mentioned.
Posted
Updated 27-Jan-12 0:04am
v2
Comments
Herman<T>.Instance 27-Jan-12 9:20am    
try Request.UserHostAddress in stead of Request.ServerVariables("HTTP_REFERER")

1 solution

I had this problem a couple of years ago, but I've managed to find the web page I created. (I found this workaround somewhere on the web, sorry don't remeber).
JavaScript
//bug in explorer forzo la ri-creazione dell'header a mano.
var isOpera, isIE = false;
if(typeof(window.opera) != 'undefined'){isOpera = true;}
if(!isOpera && navigator.userAgent.indexOf('Internet Explorer')){isIE = true;}

function goto(url){
  location.href = url;
}

//ricreo per explorer
if(isIE){
  function goto(url){
    var referLink = document.createElement('a');
    referLink.href = url;
    document.body.appendChild(referLink);
    referLink.click();
  }
}

This forces IE to recreate the header when clicking on a link as, sometimes, explorer fails to send headers for some unknown reason. You'll have to put this fix on your www.example1.com website.
Can't you pass some crypted variabiles by querystring?
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900