·您现在的位置: 云翼网络 >> 文章中心 >> 网站建设 >> 网站建设开发 >> ASP.NET网站开发 >> C#获得当前页面客户端的IP 用于监测获取某个页面上用户的客户端真实IP地址
|
1 /// <summary> 2 /// 获得当前页面客户端的IP 3 /// </summary> 4 /// <returns>当前页面客户端的IP</returns> 5 public static string GetIP() 6 { 7 8 9 string result = String.Empty;10 11 result = HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"];12 if (null == result || result == String.Empty)13 {14 result = HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"];15 }16 17 if (null == result || result == String.Empty)18 {19 result = HttpContext.Current.Request.UserHostAddress;20 }21 22 if (null == result || result == String.Empty || !ValidateUtils.IsIP(result))23 {24 return "0.0.0.0";25 }26 27 return result;28 29 }
转自:记住你 C#社区 http://www.jizhuni.com/thread-533-1-1.html