我有IP地址,但出于某种原因,我可以正确解析名称以显示本地计算机名称。我尝试了几件事,他们都显示服务器主机名?如何在c#和asp.net中获取客户端主机名,本地计算机名称和用户名
ipadd = HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"];
IPAddress myIP = IPAddress.Parse(ipadd);
IPHostEntry GetIPHost = Dns.GetHostEntry(myIP);
//userhostname = System.Environment.MachineName;
//userhostname = Dns.GetHostName(); //Resolve ServerHostName not computer
//userhostname = HttpContext.Current.Request.UserHostName;
//userhostname = HttpContext.Current.Request.UserAgent;
userhostname = GetIPHost.HostName;
对于用户名,我特林使用
nametext = WindowsIdentity.GetCurrent().Name;
//Shows server name when deployed on server
//when debuging and running localy shows correctly current user logged in
//nametext = HttpContext.Current.Request.ServerVariables["LOGON_USER"];
// not returning anything
我交换身份验证和没有结果
<authentication mode="Forms">
<authentication mode="Windows">
是互联网上或Intranet上的这个运行?如果它在网络上运行,出于安全原因,您可能无法访问诸如主机名和Windows用户名等详细信息。我从来没有尝试过,但似乎这些事情可能会受到保护/不可用。 – Jim 2012-07-10 18:19:51
这是在内部网上。我认为问题是在IIS上的身份验证模式中,我现在已经在IIS 7中启用匿名身份验证。我正在考虑使用JavaScript函数来检索此信息。 – laspalmos 2012-07-10 18:29:27
您需要打开Windows身份验证才能正常工作,我相信。 – Jim 2012-07-10 18:46:44