tags:

views:

53

answers:

2

I am placing a JS file to remote server(s). I d like to know where the request is coming from.

ie : i have a js on google.com and upon user click on the link that s produced by js, it triggers some c# code on my server, but i also have the same js on yahoo.com and i d like to be able to know where the request is coming from.

How to find this ?

+1  A: 

Following on your own lead for "System.Web.HttpContext.Current.Request.ServerVariables", the MSDN documentation for the ServerVariables property contains some sample code on how to retrieve all available named server variables:

int loop1, loop2;
NameValueCollection coll;

// Load ServerVariable collection into NameValueCollection object.
coll=Request.ServerVariables; 
// Get names of all keys into a string array. 
String[] arr1 = coll.AllKeys; 
for (loop1 = 0; loop1 < arr1.Length; loop1++) 
{
   Response.Write("Key: " + arr1[loop1] + "<br>");
   String[] arr2=coll.GetValues(arr1[loop1]);
   for (loop2 = 0; loop2 < arr2.Length; loop2++) {
      Response.Write("Value " + loop2 + ": " + Server.HtmlEncode(arr2[loop2]) + "<br>");
   }
}

Furthermore, it also contains a link to all server variables supported by IIS

For example, the "REMOTE_HOST" variable will give you:

The name of the host that is making the request. If the server does not have this information, it will set REMOTE_ADDR and leave this empty.

Miguel Sevilla
+2  A: 

In ASP.NET, the referring page is given by Request.UrlReferrer as a Uri object.

This is also available as Request.ServerVariables["HTTP_REFERER"] as a string.

Lachlan Roche