/// <summary> /// 快网CDN专用取IP方法 ygj 2011-6-15 团卡前台用的快网CDN,必须掉这个方法 /// </summary> /// <returns></returns> public static string getRealIp_byKW() { string UserIP; if (!string.IsNullOrEmpty(HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"])) { UserIP = HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"]; } else { UserIP = HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"]; } UserIP = UserIP.Replace(";", ","); UserIP = UserIP.Replace(";", ","); UserIP = UserIP.Replace(",", ","); UserIP = StringUtil.GetFirstIp(UserIP); return(UserIP); }
public static string getRealIp() { string UserIP; if (HttpContext.Current.Request.Headers["Cdn-Src-Ip"] != null) { UserIP = HttpContext.Current.Request.Headers["Cdn-Src-Ip"]; } else if (!string.IsNullOrEmpty(HttpContext.Current.Request.ServerVariables["HTTP_VIA"])) //得到穿过代理服务器的ip地址 { if (!string.IsNullOrEmpty(HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"])) { UserIP = StringUtil.GetFirstIp(HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"]); } else { UserIP = HttpContext.Current.Request.ServerVariables["HTTP_VIA"]; } } else { if (!string.IsNullOrEmpty(HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"])) { UserIP = HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"]; } else { UserIP = HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"]; } UserIP = UserIP.Replace(";", ","); UserIP = UserIP.Replace(";", ","); UserIP = UserIP.Replace(",", ","); UserIP = StringUtil.GetFirstIp(UserIP); } return(UserIP); }