.NET Framework -> GetClientIp
private string GetClientIp()
{
string ip = "";
if (HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"] != null)
{
ip = HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
if (!string.IsNullOrEmpty(ip))
{
string[] ipRange = ip.Split(",".ToCharArray());
ip = ipRange[0];
}
}
if (string.IsNullOrEmpty(ip))
{
if (HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"] != null)
ip = HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"].ToString();
}
return ip.Trim();
}
Categories: Genel