/// <summary> /// 无视代理,返回真实IP /// </summary> /// <returns></returns> public static string GetClientIP() { if (HttpContext.Current.Request.ServerVariables["HTTP_VIA"] != null) // using proxy { return HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"].Split(new char[] { ',' })[0].ToString(); // Return real client IP. } else// not using proxy or can't get the Client IP { return HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"].ToString(); //While it can't get the Client IP, it will return proxy IP. } }
/// <summary>/// 无视代理,返回真实IP/// </summary>/// <returns></returns>public static string GetClientIP(){if (HttpContext.Current.Request.ServerVariables["HTTP_VIA"] != null) // using proxy{return HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"].Split(new char[] { ',' })[0].ToString(); // Return real client IP.}else// not using proxy or can't get the Client IP{return HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"].ToString(); //While it can't get the Client IP, it will return proxy IP.}}