I am using the following code to obtain the user I.P. address but something strange is happening. I am, receiving the same ip address every time no matter if I am on my desk
Try this;
if (!String.IsNullOrEmpty(HttpContext.Current.Request.ServerVariables["HTTP_CLIENT_IP"]))
ipAddress = HttpContext.Current.Request.ServerVariables["HTTP_CLIENT_IP"];
else
ipAddress = HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"];
Request.UserHostAddress
return server IP which IIS run on.
I hope this will be resolved by this time, I ran into same issue. Like you we I knew the IP address was one of the server on the network (Load Balancer).
If your solution is load balanced web servers, then there are high chances that your load balancer is updating the request header information, rerouting through some software load balancer or something.
In case on local testing, update the router configuration to pass the request details. read some router configuration manual, there should be something which will have this setting. :)
Supply your router information, someone will have router/hardware knowledge on this.
I am not a hardware expert, but ask your network administrator to either pass-on the header info as is or at least update "X-Forwarded-For" information. So you can build code to read this information consistently.
Find more information about the traffic routing techniques used in industry and issues here.
Sanjay
see this link http://thepcspy.com/read/getting_the_real_ip_of_your_users/
// Look for a proxy address first
_ip = Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
// If there is no proxy, get the standard remote address
if (_ip == null || _ip.ToLower() == "unknown")
_ip = Request.ServerVariables["REMOTE_ADDR"];