How do I get the visitor’s IP address?

How do I get the visitor’s IP address?

There are two possible ways, either using:


HttpContext.Current.Request.UserHostAddress;

or using

HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"];

Furthermore there is information that the below line retrieves the actual IP address and not the Proxy:

HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"];

However this hasn’t been tested yet.

Leave a Reply

Your email address will not be published. Required fields are marked *

Back To Top