C#获得当前页面客户端的IP 用于监测获取某个页面上用户的客户端真实IP地址


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

C#获得当前页面客户端的IP 用于监测获取某个页面上用户的客户端真实IP地址

上一篇:winform界面收解(1) - Ribbon界面


下一篇:【CSP-S2020】【Luogu P7075】儒略日