Search This Blog

2009-05-21

How to know the IP Address of the user who visit my site

we can track the IP address of the user if when they visit my site.

Following is the code to know the user IP address

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

To get the IP address of the machine and not the proxy use the following code
HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"];

No comments: