奇怪的获取客户端IP
1、 private string getIp()
{/*穿过代理服务器取远程用户真实IP地址:*/
if (Request.ServerVariables["HTTP_VIA"] != null)
return Request.ServerVariables["HTTP_X_FORWARDED_FOR"].ToString();
else
return Request.ServerVariables["REMOTE_ADDR"].ToString();
}
2、string ip = Request.ServerVariables.Get("Remote_Addr").ToString();
用这两种方法获取客户端IP,在另外两台服务器上都正常,唯独在一台服务器上得到的是服务器的IP,怎么回事?
------解决方案--------------------
public static string GetIPAddress()
{
string result = String.Empty;
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;
}
------解决方案--------------------不理解