日期:2014-05-17  浏览次数:20809 次

为什么获得的IP不是一段
为什么获取客户端IP,实际有时候得到好几段呢
如58.219.133.170, 127.0.0.1, 10.210.42.57
求解,求更好的代码,我的代码如下:

public static string KeHuDuanIP()
    {
        string e= HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
        if (string.IsNullOrEmpty(e))
        {
            e= HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"];
        }
        if (string.IsNullOrEmpty(e))
        {
            e= HttpContext.Current.Request.UserHostAddress;
        }
        return e;
    }
客户端IP

------解决方案--------------------
因为经过多次代理,代理服务器将它们都附加到了x forward for上。