• 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!

You are not logged in or you do not have permission to access this page. This could be due to one of several reasons:

  • You are not logged in. If you are already registered, fill in the form below to log in, or follow the "Sign Up" link to register a new account.
  • You may not have sufficient privileges to access this page. Are you trying to edit someone else's post, access administrative features or some other privileged system?
  • If you are trying to post, the administrator may have disabled your account, or it may be awaiting activation.

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

Collapse

  • wxman
    replied
    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;
    }

    Leave a comment:


  • Durbs
    replied
    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.

    Leave a comment:


  • Jaws
    replied
    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".

    Leave a comment:


  • wxman
    started a topic C#.NET getting remote host name (not web server name)

    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!

Working...
X