我试了这个Request.ServerVariables["HTTP_X_FORWARDED_FOR"]好像没有用!不知道是不是还有其它的函数。大家帮帮忙谢谢了。。

解决方案 »

  1.   

    Request.ServerVariables["HTTP_X_FORWARDED_FOR"].ToString();在取值前先判断一下Request.ServerVariables["HTTP_X_FORWARDED_FOR"]是否为null。
      

  2.   

    //下面是我写的一个透过代理取IP的函数。
    public static string getUserIP()
    {
    if(HttpContext.Current.Request.ServerVariables["HTTP_VIA"]!=null)
    {  
    return HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"].ToString();  
    }
    else
    {  
    return HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"].ToString();  
    }  
    }