获取客户端IP
1 /// <summary> 2 /// 获取用户IP地址 3 /// </summary> 4 /// <returns></returns> 5 public static string GetClientIP() 6 { 7 8 string user_IP = string.Empty; 9 if (System.Web.HttpContext.Current.Request.ServerVariables["HTTP_VIA"] != null) 10 { 11 if (System.Web.HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"] != null) 12 { 13 user_IP = System.Web.HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"].ToString(); 14 } 15 else 16 { 17 user_IP = System.Web.HttpContext.Current.Request.UserHostAddress; 18 } 19 } 20 else 21 { 22 user_IP = System.Web.HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"].ToString(); 23 } 24 return user_IP; 25 } 26
本文来自博客园,作者:mushishi,转载请注明原文链接:https://www.cnblogs.com/mushishi/p/3208086.html