In my web application i have registration form, when user register i want to get his ip address of his system, how can i get using asp.net. help me please.
3 Answers
HttpContext.Current.Request.UserHostAddress;
or
HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"];
To get the IP address of the machine and not the proxy use the following code
HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
2 Comments
o.k.w
@Lance: Good point. More info on that here: en.wikipedia.org/wiki/X-Forwarded-For
Surya sasidhar
than u Mr.Lance Harper it is working but what is the sencond one and third one it is not working
HttpContext.Current.Request.UserHostAddress
1 Comment
o.k.w
Do note that for IIS7,
Request.UserHostAddress for localhost returns ::1 and not 127.0.0.1.