我有IP地址,但由于某些原因,我可以正确解析名称以显示本地计算机名称。我试了几次,所有的都显示了服务器的主机名?
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">
发布于 2012-07-11 00:25:03
使用HttpRequest.UserHostAddress
和HttpRequest.UserHostName
作为客户端IP和计算机名称。
假设您已正确配置了身份验证,则可以从IIdentity.Name
获取客户端用户。
在Page
的上下文中,您可以使用Request.UserHostAddress
、Request.UserHostName
和User.Identity.Name
。
发布于 2016-09-26 21:06:40
我使用它来显示我的intranet上的客户端语言环境机器(使用System.Net):
Dns.GetHostEntry(Request.UserHostAddress).HostName.ToString()
https://stackoverflow.com/questions/11417640
复制相似问题