public static string GetClientIP()
{
try
{
string Ip = string.Empty;
string ipList = HttpContext.Current.Request.ServerVariables["HTTP_X_CLUSTER_CLIENT_IP"];
if (!string.IsNullOrEmpty(ipList))
{
Ip = ipList.Split(',')[0];
}
else
{
Ip = HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"];
}
if (Ip.Equals("127.0.0.1"))
{
Ip = Dns.GetHostAddresses(Dns.GetHostName()).GetValue(0).ToString();
}
return Ip;
}
catch
{
throw;
}
}
You may think that why you are checking loopback (127.0.0.1).
If i am working on same machine where this app deployed then it will give me loopback insted of actual IP.
Is it right way to check loopback?