locked
About Request.UserHostName RRS feed

  • Question

  • User2050006452 posted

    Background

    • I'm making asp.Net app that work on IIS 7.5/6.0.
    • The app log client's host name and I use Request.UserHostName to know client's host name.

    My Understanding about Request.UserHostName

    1. Client request to my app.
    2. My app get Request.UserHostName
    3. .net ask host name to DNS server.
      maybe by client's IP?
    4. DNS server response client's host name.

    Question

    • Is my understanding about Request.UserHostName right?
    • How does it occur? if DNS server delay.
      Will my app wait DNS server's respnse?
    Wednesday, February 4, 2015 12:32 AM

All replies

  • User-760709272 posted

    It just looks at the REMOTE_ADDR server variable, here's the code

    public override string GetRemoteAddress()
    {
    	return this.GetServerVariable("REMOTE_ADDR");
    }
    

    Wednesday, February 4, 2015 3:54 AM
  • User2050006452 posted

    Thanks.

    You mean that Request.UserHostName just use environment valuable.

    HTTP Request Class seems same to your sample.
    https://msdn.microsoft.com/en-us/library/System.Web.HttpRequest(v=vs.110).aspx 

    Wednesday, February 4, 2015 9:08 PM
  • User753101303 posted

    Hi,

    As far as I know it doesn't do a name resolution but just take the best information available out of the incoming network frame. So you could perfectly have an IP addresss rather than a name. If you are REALLY interested in the name you could configure IIS to do the name resolution (with the corresponding performance penalty) or maybe do that by your app or later. Make sure the name is really usefull (not convinced).

    Also you could perhaps see http://referencesource.microsoft.com/ to see what happens exactly under the hood at least up to some level...

    Friday, February 6, 2015 8:01 AM