HttpRequestBase.UserHostAddress throwing error RRS feed

  • Question

  • User799750774 posted

    I am capturing some of the information on users that visit a particular section of my website and I am getting an odd error. I have a section of code that does the following.

    string userIp = request.UserHostAddress; 

    The request variable is a HttpRequestBase. At times this works just fine and I get the IP - other times it throws an error that I am not sure how to safeguard against. This is from my error log.

    "Value does not fall within the expected range.   at System.Runtime.InteropServices.Marshal.ThrowExceptionForHRInternal(Int32 errorCode, IntPtr errorInfo)   at System.Web.Hosting.IIS7WorkerRequest.GetServerVariableInternal(String name)"

    It seems that the first time I go to a page it works just fine, the error gets thrown if I do a refresh, or go quickly to another page that capturs the same variable.

    Wednesday, February 22, 2012 3:24 PM

All replies

  • User753101303 posted


    And you are doing that from where? My first thoughts would be either there is no current request when using that or could ie be that it was not prepared to handle IP v6 errors ?

    Monday, December 11, 2017 7:07 PM