How can i get IP address of client machine in C#.? I want to keep a log register for my online application and to keep IP address of logging system i want to get the IP address of client....
Advance Thanks...
How can i get IP address of client machine in C#.? I want to keep a log register for my online application and to keep IP address of logging system i want to get the IP address of client....
Advance Thanks...
HttpContext.Current.Request.UserHostAddress
This doesn't attempt to take into account proxies. For that, you can use Request.ServerVariables["HTTP_X_FORWARDED_FOR"]
. However, make sure you're not trusting that blindly, since it could be forged. It's better to keep a whitelist of IPs for which you trust it.
String clientIP =
(HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"]==null)?
HttpContext.Current.Request.UserHostAddress:
HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"];