#region 获取 客户端IP /// <summary> /// 获取客户端真实IP /// </summary> /// <returns></returns> public static string GetClientRealIP() { string ip; try { HttpRequest request = HttpContext.Current.Request; if (request.ServerVariables["HTTP_VIA"] != null) { ip = request.ServerVariables["HTTP_X_FORWARDED_FOR"].ToString().Split(',')[0].Trim(); } else { ip = request.UserHostAddress; } } catch (Exception e) { //throw e; //如果真实IP获取不到 ip = GetClientViaIP(); } return ip; } /// <summary> /// 获取客户端IP /// </summary> /// <returns></returns> public static string GetClientViaIP() { string viaIp = null; try { HttpRequest request = HttpContext.Current.Request; if (request.ServerVariables["HTTP_VIA"] != null) { viaIp = request.UserHostAddress; } } catch (Exception e) { //throw e; viaIp= "000.000.0.0"; } return viaIp; } #endregion public static string GetClientHostName() { string str = null; try { HttpRequest request = HttpContext.Current.Request; str = request.ServerVariables["REMOTE_HOST"]; } catch (Exception) { str = null; } return str; }