• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2480
  • Last Modified:

How to get the referral site URL

How do I capture the referral site(From which the user came to my site. The link on which brought my user to my site) and take the user back to that page when he is done with mine?

0
netsol07
Asked:
netsol07
  • 3
1 Solution
 
RedKelvinCommented:
Hi,
To get the referring Url, you can use

Request.UrlReferrer.ToString()

and you can use the response redirect, to redirect the user back to that url, so the complete operation would be like this

Response.Redirect(Request.UrlReferrer.ToString())
0
 
RedKelvinCommented:
oh, I should also point out that you need to use the System.Web.HttpContext.Current namespace for the request and response objects. put this at the top of your code outside the class


imports System.Web.HttpContext.Current

Open in new window

0
 
nisarkhanCommented:
You can use Request.ServerVariables("HTTP_REFERER") to get the referral URL in your ASP pages. Read more about the Request.ServerVariables collection here:

http://www.aspdev.org/articles/asp-servervariables/ 
0
 
netsol07Author Commented:
Hi RedKelvin,

I've did what you suggested as my application is in asp.net.
I'm wondering what would be the better way to test it because I'm always getting "" for refuri.
(I have placed the new site link in one of my old apps and ran from there)
0
 
RedKelvinCommented:
did the previous page link to that page, otherwise the referrer will be ""
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now