public static string GetIp(HttpContext context) { string result = String.Empty; result = context.Request.ServerVariables["HTTP_X_FORWARDED_FOR"]; //获取代理ip if (string.IsNullOrEmpty(result)) { result = context.Request.ServerVariables["REMOTE_ADDR"]; //发出请求的远程主机的IP地址。 } if (string.IsNullOrEmpty(result)) { result = HttpContext.Current.Request.UserHostAddress; } return result; }