Click here to Skip to main content
15,905,967 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
There are many restriction in the use of both Urlreferrer and HTTP_REFERRER. So, is there any alternative for the both.

Actually I am facing the problem the both are working fine on my local machine but not giving result on live environment.

Is there any alternative to the above.

Here is the scenarios:

There is a site say http://mysite.com/login.aspx - it captures the incoming urls at Page_Load

user is coming from other sites like;

http://abc.com/travel.aspx
http://bnc.org/getinto.aspx

Any suggestion/solution will be most appreciable.
Posted
Updated 19-Jul-22 13:26pm
Comments
[no name] 26-Aug-10 8:19am    
Your example is not clear. What is wrong with?
Gaurav Aroraa 27-Aug-10 7:30am    
Actually main issue is I used both urlreferrer and HTTP_REFERRER to detect incoming user urls. Which is working fine in local and test environment but its not working in production environment. All environments have same configuration and securities.

eg. on site abc.com there is a link which send user to site xyz.com now in the default landing page of xyz.com we are checking the incoming url which is abc.com in this case by using above and facing problem in production environment

You will find value in the Request.UrlReferrer only if the current request is initiated by clicking on a Link at the current Asp.net web application. Otherwise, if the request is redirected to a page (Be it from the current web site or a different web site) using Response.Redirect, you will find the Request.UrlReferrer value to be null.

As a workaround, when you redirect to your target page (From within the current site or from the other sites), you can append a QueryString parameter (Say, http://www.mysite.com/login.aspx?FromUrl=http://abc.com/travel.aspx, Making sure you encode the FromUrl value). This QueryString parameter value will contain the URL from where the current request is originated.

I used this technique in one of my project. Hope, this will help you.
 
Share this answer
 
Comments
Gaurav Aroraa 26-Aug-10 14:45pm    
Sorry I did not agree with you the same contains value when user coming from outside current application. I wrote its working fine in locally but the problem is on production.
Please check this : http://stackoverflow.com/questions/3524954/how-to-validate-incoming-urls

I know the querystring technique but its hard to change each and evrylink on any application if the querystring value will change in future
Al-Farooque Shubho 27-Aug-10 0:01am    
It's OK if you don't agree with me.

I am not clear about your local environment. But, in real system, the Request.UrlReferrer will have value only if user clicked a HyperLink to navigate to this page. Check out this link : http://authors.aspalliance.com/aspxtreme/sys/web/httprequestclassurlreferrer.aspx

I also had an MSDN reference, need post that once I find.
Gaurav Aroraa 30-Oct-14 3:13am    
@AlFarooqueShubho - we found one another way to do this. I will be posted here. In between can you please post MSDN link, you mentioned.
Gaurav Aroraa 25-Oct-14 15:28pm    
laterally, I noticed there is no good solution available for this. I accepted your answer
I found an easier solution in vb.net

Dim MyReferrer As Object = Request.UrlReferrer()
If Len(MyReferrer) > 0 Then
MsgBox(MyReferrer.ToString)
Else
MsgBox("it's null")
End If
Aloha,
Tony
 
Share this answer
 
Comments
CHill60 20-Jul-22 3:20am    
Except the question was tagged C# and whilst "easier" this will put a message box up on the non-existent screen on the host server. Strictly speaking a string of length zero is not null it's empty. None of this helps anyone overcome the actual problem, unlike the 10 year old accepted solution.

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