我怎样才能在c#中获得计算机的名称,我需要名称而不是IP
用户名
txtUserIP.Text = HttpContext.Current.Request.UserHostAddress
HttpContext.Current.Request.LogonUserIdentity.Name
它给出了给定 IP 的
,我需要:
- 的名称:
HttpContext
- 计算机应用用户
它需要开头的
HttpContext.Current.Request.LogonUserIdentity.Name
it's given the user name
txtUserIP.Text = HttpContext.Current.Request.UserHostAddress
it's given the IP
and I need:
- the name of the computer
- aplicative user
it's need to start with: HttpContext
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
UserHostName 获取客户端的 DNS 名称,这足够了吗?
最初编辑
Oskar,非常正确地在他的评论中链接了另一个问题,指出您不能假设设置了此变量,服务器从请求中的 UserAgent 标头获取数据,并且该数据特别被删除了很多(匿名代理)等)所以是的,它可能可用,不,你不能假设它是
UserHostName gets the DNS name of the client, is that sufficient?
edit
Oskar originally, and quite correctly, linked another question in his comment pointing out that you cannot assume this variable is set, the server gets it data from the UserAgent header in the request and this data in particular is stripped out a lot (anonymous proxies etc) so yes it may be available, no you cannot assume it is
HttpContext.Current.Server.MachineName
包含服务器的名称。您无法获取客户端计算机的名称,因为它不是随请求一起发送的。HttpContext.Current.Server.MachineName
contains the name of the server. You can't get the name of the client computer, as it isn't sent with a request.无法使用 HttpContext 做到这一点。你能用这个吗?:
Can't do it with HttpContext. Could you use this?:
本地计算机的 DNS 主机名
DNS host name of the local computer