コード例 #1
0
        public static string GetIP(ClientIpType clientIpType)
        {
            string IP = "";

            try
            {
                switch (clientIpType)
                {
                case ClientIpType.SearchProxy:     // 判斷是否有使用 Proxy
                    if (HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"] == "")
                    {
                        IP = HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"];
                    }
                    else     // proxy
                    {
                        IP = HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
                    }
                    break;

                case ClientIpType.LastPage:      // 上一頁的網址(從哪來)
                    IP = HttpContext.Current.Request.ServerVariables["HTTP_REFERER"];
                    break;

                default:     // 直接回傳抓到的 client IP
                    IP = HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"];
                    break;
                }
            }
            catch
            {
            }
            return(IP);
        }
コード例 #2
0
 static QiuxunApiController()
 {
     if (System.Enum.TryParse(ConfigurationManager.AppSettings["client_ip_switch"], out _clientIpType))
     {
         _clientIpType = ClientIpType.TcpIp;
     }
 }
コード例 #3
0
 static ApiInterfaceControl()
 {
     if (!System.Enum.TryParse <ClientIpType>(ConfigurationManager.AppSettings["client_ip_switch"], out _clientIpType))
     {
         _clientIpType = ClientIpType.TcpIp;
     }
 }