1 using System;
2 using System.Web;
3
4
5 namespace Plugins
6 {
7 public class ClientIP
8 {
9 public static string GetUserIP()
10 {
11 string result = String.Empty;
12
13 result = HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
14 if (null == result || result == String.Empty)
15 {
16 result = HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"];
17 }
18
19 if (null == result || result == String.Empty)
20 {
21 result = HttpContext.Current.Request.UserHostAddress;
22 }
23
24 if (null == result || result == String.Empty)
25 {
26 return "0.0.0.0";
27 }
28
29 return result;
30 }
31 }
32 }
//注释就不写了,自己调用就行了。