Feb 22, 2012 03:24 PM|mitchm521|LINK
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.