我怎样才能在c#中获得计算机的名称,我需要名称而不是IP

发布于 2025-01-01 07:29:37 字数 277 浏览 1 评论 0原文

用户名

txtUserIP.Text = HttpContext.Current.Request.UserHostAddress

HttpContext.Current.Request.LogonUserIdentity.Name 它给出了给定 IP 的

,我需要:

  1. 的名称:HttpContext
  2. 计算机应用用户

它需要开头的

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:

  1. the name of the computer
  2. aplicative user

it's need to start with: HttpContext

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

橘寄 2025-01-08 07:29:37

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

池木 2025-01-08 07:29:37

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.

孤君无依 2025-01-08 07:29:37

无法使用 HttpContext 做到这一点。你能用这个吗?:

var IpToHost = Dns.GetHostEntry(ipaddress);

Can't do it with HttpContext. Could you use this?:

var IpToHost = Dns.GetHostEntry(ipaddress);
美人如玉 2025-01-08 07:29:37

本地计算机的 DNS 主机名

String hostName = Dns.GetHostName();

DNS host name of the local computer

String hostName = Dns.GetHostName();
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文