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.N
Try this it works for me
string clientMachineName;
clientMachineName = (Dns.GetHostEntry(Request.ServerVariables["remote_addr"]).HostName);
Response.Write(clientMachineName);
As @blowdark wrote it's impossible actually to get client machine name and host name is not client machine name. Let's look at what from request you can have?
That's all. IP address is an IP which is given by your Internet provider, and host name is name of some provider machine which Internet traffic passes through. You even cannot get in simple way user machine local IP address in Internet provider network.
If your application has load balancer or proxy then you need to read HTTP_X_FORWARDED_FOR header (by default) to get request client IP. But it's provider IP again.
So, from request IP you cannot get real client machine name in general. In HTTP headers browsers also don't pass machine name. Perhaps with some kind of hacks you can get machine name asking provider server, but that's out of scope.
Machine names are a concept for local networks only, and local AD networks/forests at that. Once you expose your site on the internet machine names no longer make sense, instead you get DNS names.
So, for example, on my the work network my laptop name resolves to bdorrans01.redmond.contoso.com. But if I browse to a web site from home my current ip address resolves to c-98-203-143-14.hsd1.wa.comcast.net.
You are taking the FQDN and dropping everything after the first period/full stop. That works in an AD environment (sort of), and your code would see bdorrans01 internally, but it would see c-98-203-143-14 externally.
Even internally within a multi-forest AD it would also be wrong if your web site was hosted in another forest, for example if you site lived on example.europe.contoso.com, your code would get a machine name of bdorrans01, but my machine wouldn't be in the same forest, and if you tried to ping it, or map to a network drive it wouldn't be found, because you would be looking for bdorrans01 in europe.contoso.com, not redmond.contoso.com where it actually is.
Also your code assumes that resolving an IP address will produce a fully qualified domain name, this isn't true in a lot of cases, you could just get an IP address back, so you may see 1.2.3.4 and your code would give a machine name of 1. Worse yet it'll not do anything to an IPv6 address as they use colons to separate, 2001:db8:85a3:8d3:1319:8a2e:370:7348
So your premise is incorrect - and you need to find a different way to do what you're trying to do. Why do you believe you need the machine name anyway?
Once you enable browser to allow creation of active-x objects, for IE you can write below javascript code to get client computer name as:
var WinNetwork = new ActiveXObject("WScript.Network");
var ComputerName = WinNetwork.ComputerName;