locked
Getting computer client name RRS feed

  • Question

  • User-1634117515 posted

    Hi

    I'm trying to get the name of the client computer with this code 

    string clientMachineName;
                IPAddress iP = null;
                IPAddress.TryParse(Request.ServerVariables["REMOTE_HOST"],out iP);
    clientMachineName = Dns.GetHostEntry(iP).HostName;

    on the computer where I'm programming it worked but when it's on a server and I open the page in another computer it sends me an error:

    No such host is known
    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 
    
    Exception Details: System.Net.Sockets.SocketException: No such host is known
    
    Source Error: 
    
    An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

    how can I do that 
     

    Tuesday, July 9, 2019 8:35 PM

All replies

  • User-821857111 posted

    You can't get the name of the client machine. That information is not accessible to code that executes on the web server - unless the client and the web server are the same machine as if the case when you are running the application on your dev machine. The information is not accessible to code that executes in the browser, either.

    If you want to uniquely identify a user, you should implement some kind of login based authentication.

    Tuesday, July 9, 2019 9:34 PM
  • User753101303 posted

    Hi,

    It should work if both machines are in the same network. You should be prepared for this to fail if this is not the case. The name of a machine doesn't make sense outside its own local network (unless a name is explicitly exposed as done for web servers).

    Tuesday, July 9, 2019 9:38 PM
  • User409696431 posted

    I am curious: Why would you want to do that?

    First, unless this is an intranet site, all computers on the same site network, you can't do what you want.

    And if it is an internet (public) site, the information would be useless to you.  If I named my computer "Hal" or "Daisy", there is no reason to assume no one else named their computer "Hal" or "Daisy".  And what a visitor to your public site names their personal computer is not really for your eyes.

    Wednesday, July 10, 2019 11:32 PM
  • User-1634117515 posted

    this is an Intranet the server is in one VLAN and the clients are in another, what I wanna do is get the computer name and with that get all the information that I have in one Database and work with that information 

    Thursday, July 11, 2019 1:19 PM
  • User753101303 posted

    Call your network admin to discuss about that. IMO it might be even forbidden anyway in your company.

    Ok but which real value do you expect from having a machine name? You don't have already a user name?

    Thursday, July 11, 2019 2:17 PM