|
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#社區(qū) http://www.jizhuni.com/thread-533-1-1.html
新聞熱點
疑難解答