" + User....">

How to find the remote host name in asp.net?

I used this code to find the name of the remote user:

banner_label.Text = "Welcome, <B>" + User.Identity.Name + "</B>!"

I would also like to find the name of the remote host. My production environment will be a corporate intranet with an active directory.

+3
source share
4 answers

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
+3

, HttpContext.Current.Request.ServerVariables["REMOTE_HOST"], , . , , .

, , .

+1

,

Request.UserHostName

:

, , , , , , - , .

0

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.

0
source

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


All Articles