Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get Client Machine Name in ASP.NET / C#?

Tags:

c#

asp.net

I have application want to get user machine name, here I can retrieve and it works fine in localhost.

string clientPCName;
string[] computer_name = System.Net.Dns.GetHostEntry(
Request.ServerVariables["remote_host"]).HostName.Split(new Char[] { '.' });
clientPCName = computer_name[0].ToString(); 

In local it returns exactly my computer name.
But on server I get result like this: 0x57364794
Any solution?

like image 799
Shaahin Avatar asked May 28 '11 10:05

Shaahin


People also ask

How do I find my client computer name?

In order to retrieve the client's computer name, you will have to query the DNS server with the client's IP. The IP can be easily retrieved by using the ASP.NET Request object with its UserHostAddress property.


1 Answers

Try this it works for me

string clientMachineName;
clientMachineName = (Dns.GetHostEntry(Request.ServerVariables["remote_addr"]).HostName);
Response.Write(clientMachineName);
like image 199
Ahmed Avatar answered Nov 07 '22 14:11

Ahmed