vb.net 如何获取客户端的计算机名称
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/22269268/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to get client's computer name
提问by Mahdi_Nine
I saw this question in another post but the solution did not work correctly. I use:
我在另一篇文章中看到了这个问题,但该解决方案无法正常工作。我用:
System.Net.Dns.GetHostEntry(HttpContext.Current.Request.ServerVariables.Item("REMOTE_HOST")).HostName
This worked correctly on localhost but on server it has problems and returns an empty string. Any idea?
这在本地主机上正常工作,但在服务器上它有问题并返回一个空字符串。任何的想法?
采纳答案by Ramon Araujo
Two things to consider:
需要考虑的两件事:
- Take into account that
HttpContext.Current.Request.ServerVariables.Item("REMOTE_HOST") will return the name of the host making the request, not the address. - Try doing
System.Net.Dns.GetHostByAddress(Request.ServerVariables.Item("REMOTE_HOST")).HostNameinstead.
- 考虑到
HttpContext.Current.Request.ServerVariables.Item("REMOTE_HOST") 将返回发出请求的主机的名称,而不是地址。 - 尝试做
System.Net.Dns.GetHostByAddress(Request.ServerVariables.Item("REMOTE_HOST")).HostName。
You can find a list of the Server Variables at Microsoft's MSDN website.
您可以在 Microsoft 的 MSDN 网站上找到服务器变量列表。
Hope that helps,
希望有所帮助,
回答by suresh pareek
To get client IP address use
获取客户端 IP 地址使用
HttpContext.Current.Request.UserHostAddress.ToString
or
或者
HttpContext.Current.Request.UserHostName
To get client browser use
获取客户端浏览器使用
HttpContext.Current.Request.Browser.Browser
回答by Massimiliano Mirelli
I find out that already in VS2010 "GetHostByAddress" is deprecated.
Instead, use: System.Net.Dns.GetHostEntry(HttpContext.Current.Request.ServerVariables["REMOTE_HOST"])
我发现 VS2010 中的“GetHostByAddress”已被弃用。相反,使用:System.Net.Dns.GetHostEntry(HttpContext.Current.Request.ServerVariables["REMOTE_HOST"])

