How to get and display the current viewer IP address in a text box?
+6
A:
You could use the HttpRequest.UserHostAddress property, or the REMOTE_ADDR key of the HttpRequest.ServerVariables collection, they are both string
, and you only have to assign its value to your TextBox:
HttpContext.Current.Request.UserHostAddress;
or
HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"];
CMS
2009-07-21 05:50:45
This will, of course, only get the IP address that the request came from - which might (thanks to proxies, NAT, etc) not be any that actually belong to the visitor's computer (but there is no way to reliably gather that information).
David Dorward
2009-07-21 08:35:00