Getting the referrer web server name

I host the JS file on remote servers. I would like to know where the request comes from.

that is: I have js on google.com, and when I click on the link created by js, it runs some C # code on my server, but I also have the same js on yahoo.com, and id likes to be able to Find out where the request comes from.

How to find it?

+3
source share
4 answers

In ASP.NET, the reference page is defined Request.UrlReferreras a Uri object .

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

+5
source

System.Environment.MachineName must contain the server name.

+7
source
Request.ServerVariables["SERVER_NAME"]

:

Request.ServerVariables["SERVER_PORT"]
+2

"System.Web.HttpContext.Current.Request.ServerVariables", MSDN ServerVariables :

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>");
   }
}

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

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

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

0
source

Source: https://habr.com/ru/post/1736252/


All Articles