ASP.NET Request.UserHostName not containing hostname

I need to save the host name of the requesting computer in the database if a new dataset is created. To clearly indicate this to the user (all this is an internal company), we display this as three text fields in the form that the user fills out. These three text fields are populated like this:

protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            txtHostname.Text = Request.UserHostName.ToString();
            txtIPAdress.Text = Request.UserHostAddress.ToString();
            txtWindowsLogin.Text = Request.LogonUserIdentity.Name.ToString();
        }
    }

However, no matter which client I tested, the reverse IP lookup, which should indicate the host name in Request.UserHostname, does not work, so the field is populated with the IP address. If I use nslookup on the server, the reverse works fine. Any hints on me where I could start? Many thanks.

+5
source share
2 answers

IIS. Dns.GetHostEntry , .

, . Dns.GetHostEntry, .

, :

public static string ReverseLookup(string ip)
{
    if (string.IsNullOrEmpty(ip)) return ip;

     try 
     {
       return Dns.GetHostEntry(ip).Select(entry => entry.HostName).FirstOrDefault() ?? ip;
     } 
     catch(SocketException) { return ip; }
}
+3

Page.Request.ServerVariables [ "HTTP_HOST" ] ToUpper();.

.

0

All Articles