For HttpContext.Current.Request.UserHostAddress If the customer is using a proxy, they will not get the real IP
To obtain the real IP address of the client through the proxy server, it is necessary to use Request.ServerVariables ("Http_x_forwarded_for") to read.
However, it is important to note that not every proxy server can use Request.ServerVariables ("Http_x_forwarded_for") to read the client's real IP, some of which are read by this method is still the proxy server IP.
It is also important to note that if the client is not accessed through a proxy server, the value taken with Request.ServerVariables ("Http_x_forwarded_for") will be empty. Therefore, if you want to use this method in your program, you can do this:
String strIp = httpcontext.current.request.servervariables["Http_x_forwarded_for"];
if (string. IsNullOrEmpty (strIp))
{
StrIp = httpcontext.current.request.servervariables["REMOTE_ADDR"];
}
if (Strip.indexof (', ') > 1)
{
strIp = strip.substring (0, Strip.indexof (', '));
}
C # Get Client IP