Hi,
I used code like this to find the remote user name:
banner_label.Text = "Welcome, <B>" + User.Identity.Name + "</B>!"
I'd also like to find the remote host name. My production environment will be a corporate intranet with active directory.
Hi,
I used code like this to find the remote user name:
banner_label.Text = "Welcome, <B>" + User.Identity.Name + "</B>!"
I'd also like to find the remote host name. My production environment will be a corporate intranet with active directory.
maybe this would work for you
Request.UserHostName
edit:
i think what you're trying to do will not working over the internet, what you're trying to get is the name of the computer, which will not be transmitted with the request to the server.
I believe you can use HttpContext.Current.Request.ServerVariables["REMOTE_HOST"], but be warned that the information is pretty unreliable. Anything being sent to you can be spoofed.
Also, I don't think this will work over the internet.
I googled around and found Request.UserHostName, but this only returned 127.0.0.1 in my development environment.
I tried this
System.Net.DNS.GetHostName
And that returned my hostname successfully. However since I'm still in dev, with my client and server on the same machine, I still need to test to make sure its actually giving me the remote host name instead of the server's name.
You're on an Intranet, so Request.UserHostName should work well for you. If you have a complex network, some of the routers may not let that info through, but...
Here's something similar I did in an app at a previous job, 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 + ")";
I then record this string in the database with every login attempt.
Edit: Skimmed over your reply above... thought this code did what you're asking for, let me go test it and see.
Not sure why that code above worked at my previous job. It wasn't reliable, which is why I put that if statement around it, but I thought it returned the host name semi-reliably... Posts online say it has something to do with anonymous access.
Anyway, this gets you what you want, and should work reliably since you're on an Intranet:
System.Net.Dns.GetHostEntry(userHost).HostName