views:

133

answers:

2

This is an ASP question, not ASP.Net.

Assume there are two sites:

  1. www.domain-1.com
  2. www.domain-2.com

www.domain-1.com has a redirection URL in IIS that points to www.domain-2.com. In www.domain-2.com, I need to know the URL of the referring site (e.g. in this case, it would be www.domain-1.com). How is this done?

+1  A: 

You can use the server variable HTTP_REFERER

See http://www.w3schools.com/asp/coll_servervariables.asp for more info.

Shoban
From W3Schools:HTTP_REFERER: Returns a string containing the URL of the page that referred the request to the current page using an <a> tag. If the page is redirected, HTTP_REFERER is emptyThe page is redirected. So, HTTP_REFERER is no good.
StackOverflowNewbie
+3  A: 

referer = Request.ServerVariables ("HTTP_REFERER")

Alex
This doesn't seem to work when it's an IIS redirect. When it's coming from an href, it works fine, though.
StackOverflowNewbie
It is not 100% reliable. It is not always set by the users browser and some spyware/privacy apps can remove it from the get request as well.However, there is any easy solution to this problem if you have access to the redirect code. You can change it to include a query string variable with the source host so www.domain-1.com redirects the user to www.domain-2.com/?source=www.domain-1.com
Alex