![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 public static string getIP()
2 {
3 string result = String.Empty;
4 result = HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
5 if (null == result || result == String.Empty)
6 {
7 result = HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"];
8 }
9 if (null == result || result == String.Empty)
10 {
11 result = HttpContext.Current.Request.UserHostAddress;
12 }
13 if (null == result || result == String.Empty)
14 {
15 return "0.0.0.0";
16 }
17 return result;
18 }