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

后端 未结 4 1499
悲哀的现实
悲哀的现实 2020-12-17 16:00

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         


        
4条回答
  •  星月不相逢
    2020-12-17 16:49

    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?

    • Request IP address (TCP/IP)
    • HTTP headers

    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.

提交回复
热议问题