-1

I have used the below code to get client computer name, however it work for some of the clients and some of the client get error

        string IPAdd = Request.UserHostName;
        IPHostEntry hostEntry = Dns.GetHostEntry(IPAdd);
        string compName = hostEntry.HostName; 

Below picture is the error: enter image description here

No such host is known.
Line 33: string IPAdd = Request.UserHostName;
Line 34: IPHostEntry hostEntry = Dns.GetHostEntry(IPAdd); <-- Throws error

Please help, thanks.

Jawad
  • 11,028
  • 3
  • 24
  • 37
Shi Jie Tio
  • 2,479
  • 5
  • 24
  • 41
  • 1
    All the collection l clients are in the same network? Are the clients connecting to the site via internet? – Chetan Jan 07 '20 at 05:04
  • 1
    have you used the debugger to see if the host is actually valid? can you ping it? – Jawad Jan 07 '20 at 05:04
  • all connected under same internet , but some of them get this error, the others work fine – Shi Jie Tio Jan 07 '20 at 05:15
  • 1
    Use debugger along with nslookup to see if the host has an ip registered – Jawad Jan 07 '20 at 05:17
  • https://stackoverflow.com/questions/4896180/dns-gethostentry-error-conditions-and-resolution-methods – Mitch Wheat Jan 07 '20 at 05:19
  • Code is somewhat strange. It starts with "The DNS name of the remote client." than tries to convert it to DNS name... Also it would be good idea to clarify that none of the error conditions you've read about in [GetHostEntry](https://learn.microsoft.com/en-us/dotnet/api/system.net.dns.gethostentry?view=netframework-4.8#System_Net_Dns_GetHostEntry_System_String_) apply to this case - otherwise some people may think you did not do any research... – Alexei Levenkov Jan 07 '20 at 05:45
  • DNS queries are not guaranteed to work, so you should expect exceptions and handle them properly (such as logging out what parameters trigger the exceptions). – Lex Li Jan 07 '20 at 14:20

1 Answers1

-1

Use this code

string compName = Environment.MachineName.ToString();

  • Actually i publish in iis, and disable the window authentification , so this method wont able detect, if i turn on the window authentifacation client need login in already , however they no want login and they dont have access in that server – Shi Jie Tio Jan 07 '20 at 05:45