如何获取客户端电脑名称

问题描述 投票:0回答:3

我在另一篇文章中看到了这个问题,但解决方案无法正常工作。 我用:

System.Net.Dns.GetHostEntry(HttpContext.Current.Request.ServerVariables.Item("REMOTE_HOST")).HostName

这在本地主机上工作正常,但在服务器上有问题并返回空字符串。 有什么想法吗?

asp.net vb.net
3个回答
2
投票

我发现 VS2010 中“GetHostByAddress”已被弃用。 相反,请使用:

System.Net.Dns.GetHostEntry(HttpContext.Current.Request.ServerVariables["REMOTE_HOST"])


1
投票

请考虑到

HttpContext.Current.Request.ServerVariables.Item("REMOTE_HOST"
) 将返回发出请求的主机的名称,而不是地址。

尝试做

System.Net.Dns.GetHostByAddress(Request.ServerVariables.Item("REMOTE_HOST")).HostName
来代替。

您可以在 Microsoft 的 MSDN 网站找到服务器变量列表。


1
投票

获取客户端IP地址使用

HttpContext.Current.Request.UserHostAddress.ToString

HttpContext.Current.Request.UserHostName

获取客户端浏览器使用

HttpContext.Current.Request.Browser.Browser
© www.soinside.com 2019 - 2024. All rights reserved.