HttpRequest request = HttpContext.Current.Request;

                if (!string.IsNullOrEmpty(request.ServerVariables["HTTP_X_FORWARDED_FOR"]))
                {
                    //ip = GetCDNIP(request.ServerVariables["HTTP_ARR_IP"]);
                    if (string.IsNullOrEmpty(ip))
                    {
                        ip = request.ServerVariables["HTTP_X_FORWARDED_FOR"].ToString().Split(',')[0].Trim();
                    }
                }
                if (string.IsNullOrEmpty(ip) || ip.Split(new char[] { '.' }, StringSplitOptions.RemoveEmptyEntries).Length != 4)
                {
                    ip = GetArrIP();
                    if (!string.IsNullOrWhiteSpace(ip) && ip.Split(new char[] { '.' }, StringSplitOptions.RemoveEmptyEntries).Length != 4)
                    {
                        ip = string.Empty;
                    }
                }
                //if (string.IsNullOrEmpty(ip))
                //{
                //    ip = GetCDNIP(null);
                //}
                if (string.IsNullOrEmpty(ip))
                {
                    ip = HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"];
                }

                if (string.IsNullOrEmpty(ip))
                {
                    ip = request.UserHostAddress;
                }

  

相关文章:

  • 2021-04-13
  • 2021-10-28
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-11-30
猜你喜欢
  • 2021-11-15
  • 2022-12-23
  • 2021-06-18
  • 2022-12-23
  • 2021-11-29
  • 2022-12-23
  • 2021-11-18
相关资源
相似解决方案