• Visitors can check out the Forum FAQ by clicking this link. You have to register before you can post: click the REGISTER link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. View our Forum Privacy Policy.
  • Want to receive the latest contracting news and advice straight to your inbox? Sign up to the ContractorUK newsletter here. Every sign up will also be entered into a draw to WIN £100 Amazon vouchers!

C#.NET getting remote host name (not web server name)

Collapse
X
  •  
  • Filter
  • Time
  • Show
Clear All
new posts

    C#.NET getting remote host name (not web server name)

    I have a bit of a problem. I am trying to get hold the PC hostname for an intranet questionnaire application I am writing.
    Basically I need to ensure that the user can only submit the form once. I was planning to capture the users computer name and store that against the record. The user does not log in to the web form in any way, just request the URL from the web server.

    However every thing I do just returns the hostname of the Web Server- not the client. I am totally stuck!!
    I have tried all the following :-


    Environment.MachineName;

    System.Net.Dns.GetHostName();

    System.Environment.GetEnvironmentVariable("COMPUTE RNAME");

    HttpContext.Current.Request.UserHostName;

    System.Net.Dns.GetHostEntry(Request.ServerVariable s["remote_addr"]).HostName.ToString();


    Has any one got any suggestion?

    The head of HR is hounding me to complete this, hence the reason why I am looking at it on a sunday afternoon!
    www.stormtrack.co.uk - My Stormchasing website.

    #2
    Originally posted by wxman View Post
    I have a bit of a problem. I am trying to get hold the PC hostname for an intranet questionnaire application I am writing.
    Basically I need to ensure that the user can only submit the form once. I was planning to capture the users computer name and store that against the record. The user does not log in to the web form in any way, just request the URL from the web server.

    However every thing I do just returns the hostname of the Web Server- not the client. I am totally stuck!!
    I have tried all the following :-


    Environment.MachineName;

    System.Net.Dns.GetHostName();

    System.Environment.GetEnvironmentVariable("COMPUTE RNAME");

    HttpContext.Current.Request.UserHostName;

    System.Net.Dns.GetHostEntry(Request.ServerVariable s["remote_addr"]).HostName.ToString();


    Has any one got any suggestion?

    The head of HR is hounding me to complete this, hence the reason why I am looking at it on a sunday afternoon!
    Does the "remote_addr" variable not return the client IP address? I think the "remote_addr" header would be overwritten by any proxy between your client and your webserver, so that might be the issue.

    Given what you have, I'd probably just store something in a cookie to signify completion of the form because these are unique to a user's profile. Although if they deleted their cookies they'd obviously be able to recomplete the form. I suppose you have that risk if they log in to another machine with the host name approach.

    Most intranet servers I've worked on have been configured to run under windows authentication, so as long as it was enabled in the web.config you could get to the user name via "HttpContext.Current.User".

    Comment


      #3
      System.Net.Dns.GetHostEntry(Request.ServerVariable s["remote_addr"]).HostName

      (currently on my Mac so cant try the above though to check it works)

      Edited, doh, just realised you'd tried that one! Maybe:

      Dim host As System.Net.IPHostEntry
      host = System.Net.Dns.GetHostByAddress(Request.ServerVari ables.Item("REMOTE_HOST"))
      strComputerName = host.HostName

      Or if you like lots of brackets and semicolons, summat like:

      System.Net.IPHostEntry host;
      host = System.Net.Dns.GetHostEntry(HttpContext.Current.Re quest.ServerVariable["REMOTE_HOST"]);
      string strComputerName = host.HostName;
      Response.Write("PC Name is: " + strComputerName);
      Last edited by Durbs; 26 July 2010, 18:55.

      Comment


        #4
        Finally got it working

        Many thnaks to Jaws and Durbs

        private string getHostName()
        {
        string hName = "";

        System.Net.IPHostEntry host = new System.Net.IPHostEntry();
        host = System.Net.Dns.GetHostEntry(HttpContext.Current.Re quest.ServerVariables["REMOTE_HOST"]);

        //Split out the host name from the FQDN
        if (host.HostName.Contains("."))
        {
        string[] sSplit = host.HostName.Split('.');
        hName = sSplit[0].ToString();
        }
        else
        {
        hName = host.HostName.ToString();
        }

        return hName;
        }
        www.stormtrack.co.uk - My Stormchasing website.

        Comment

        Working...
        X