using System.Web;

namespace Common
{
    public class IPUtil
    {
        /// <summary>
        /// 获取IP地址
        /// </summary>
        /// <returns></returns>
        public string GetClientIP()
        {
            string result = HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
            if (string.IsNullOrEmpty(result))
            {
                result = HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"];
            }

            if (string.IsNullOrEmpty(result))
            {
                result = HttpContext.Current.Request.UserHostAddress;
            }
            return result;
        }
    }
}

 

相关文章:

  • 2021-12-31
  • 2021-12-20
  • 2022-01-17
  • 2021-07-13
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-11-30
  • 2021-06-20
  • 2022-12-23
相关资源
相似解决方案