使用C#检索客户端计算机名称 [英] Retrieve Client Computer Name Using C#

查看:91
本文介绍了使用C#检索客户端计算机名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写了一个简单的ASP.NET表单,允许用户向我发送他们的需求。我必须检索他们的信息,如IP地址和他们的本地计算机的名称。我写的代码返回正确的IP地址。我没有任何问题。但是,当我尝试检索计算机名称时,它始终返回实际应用程序保留的计算机名称。在这种情况下,我的主机服务器,webserver。



我如何检索他们的电脑名称?这可能吗?



PS:使用我的asp表单发送数据的客户端计算机和保存表单的服务器位于同一网络中。



以下是我一直在尝试的代码:



  string  name1 = Environment.MachineName;  //  返回网络服务器 
string name2 = System.Net.Dns.GetHostName(); // 返回网络服务器
string name3 = System.Windows.Forms.SystemInformation.ComputerName; // 返回网络服务器
string name4 = System.Environment.GetEnvironmentVariable( COMPUTERNAME)。ToString(); // 返回网络服务器

解决方案

< blockquote>我建​​议你阅读:返回基础知识 - 在ASP.NET中获取客户端计算机名称 [ ^ ]







获取局域网中客户端计算机的IP地址:

如何重新启动机器的IP地址在局域网 [ ^ ] - mudassarkhan的答案。


I wrote a simple ASP.NET form that allows users to send me their needs. I have to retrieve their information like IP Address and their local computers' names. The codes that I wrote returns their correct IP Address. I don't have any problems with that. However, when I trying to retrive the computer name, it always returns the computer name that the actual application stays. In this case, my host server, webserver.

How can I retrieve their computer names? Is this possible?

PS: Client computers that send data using my asp form and server that holds the form are in the same network.

Here are the codes that I have been trying:

string name1 = Environment.MachineName; //returns webserver
string name2 = System.Net.Dns.GetHostName(); //returns webserver
string name3 = System.Windows.Forms.SystemInformation.ComputerName; //returns webserver
string name4 = System.Environment.GetEnvironmentVariable("COMPUTERNAME").ToString();//returns webserver

解决方案

I'd suggest to read this: Back to Basics – Get Client Computer Name in ASP.NET[^]

[EDIT]

To get ip address of client computer in LAN:
How to retervie IP Address of machine on LAN[^] - mudassarkhan's answer.


这篇关于使用C#检索客户端计算机名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆