获取真实的客户端IP地址
/// <summary>
/// 通过代理,获取真实的客户端IP地址
/// </summary>
/// <returns></returns>
protected string GetClientIPAddress()
{
try
{
string result = HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
if (null == result || result == String.Empty)
{
result = HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"];
}
if (null == result || result == String.Empty)
{
result = HttpContext.Current.Request.UserHostAddress;
}
return result;
}
catch
{
return string.Empty;
}
}