How can I get the public IP address of a user if my server is behind a router?
I'm trying to:
protected string GetIPAddress() { System.Web.HttpContext context = System.Web.HttpContext.Current; string ipAddress = context.Request.ServerVariables["HTTP_X_FORWARDED_FOR"]; if (!string.IsNullOrEmpty(ipAddress)) { string[] addresses = ipAddress.Split(','); if (addresses.Length != 0) { return addresses[0]; } } return context.Request.ServerVariables["REMOTE_ADDR"]; }
but all i get is a router gateway.
Apparently REMOTE_ADDR will not work in my case, and there will be no HTTP_X_FORWARDED_FOR .
Any ideas on how to get the user's public IP address in my case?
Thanks.
user1761123
source share