Sunday, July 3, 2011

Capture IP Address using Asp.Net

The code given below gives you the IP address of the User Accessing the site.

1) HttpContext.Current.Request.UserHostAddress;

OR

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

To get the IP Address of the machine and not the proxy use the following code:

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

2 comments: