🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
# 1、得到客户端真实IP ``` /// <summary> /// 提取开启代理/cdn服务后的客户端真实IP /// </summary> /// <returns></returns> public static string GetTrueIP() { string ip = string.Empty; string X_Forwarded_For = HttpContext.Current.Request.Headers["X-Forwarded-For"]; if (!string.IsNullOrWhiteSpace(X_Forwarded_For)) { ip = X_Forwarded_For; } else { string CF_Connecting_IP = HttpContext.Current.Request.Headers["CF-Connecting-IP"]; if (!string.IsNullOrWhiteSpace(CF_Connecting_IP)) { ip = CF_Connecting_IP; } else { ip = HttpContext.Current.Request.UserHostAddress; } } return ip; } } ``` # 使用 ``` string ip=GetTrueIP(); ```