How to find the remote host name in asp.net?
You are on the Intranet, so Request.UserHostName will work well for you. If you have a complex network, some of the routers may not miss this information, but ...
Here, I did something similar in the application on the previous task to record the IP and host name:
// NAT'ed addresses are sometimes still shown in HTTP_X_FORWARDED_FOR
string userHost = Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
if (String.IsNullOrEmpty(userHost) || String.Compare(userHost, "unknown", true) == 0)
userHost = Request.UserHostAddress;
if (String.Compare(userHost, Request.UserHostName) != 0)
userHost += " (" + Request.UserHostName + ")";
Then I write this line to the database every time I try to login.
Edit: removed your answer above ... thought this code did what you are asking for, let me check it and see.
, . , if, , -... , - .
, , , , :
System.Net.Dns.GetHostEntry(userHost).HostName
I googled around and found Request.UserHostName, but that only returned 127.0.0.1 in my development environment.
I tried this
System.Net.DNS.GetHostName
And that returned my hostname. However, since I'm still in dev, with my client and server on the same computer, I still need to test to make sure it actually gives me the remote host name instead of the server name.