Asp.net MVC中获取访客IP的方法

标签: Asp.net-MVC
发布时间: 2013/3/21 9:40:32
/// <summary>
       /// 获取IP
       /// </summary>
       /// <returns></returns>
       private string GetIP()
       {
           string ip = string.Empty;
           if (!string.IsNullOrEmpty(System.Web.HttpContext.Current.Request.ServerVariables["HTTP_VIA"]))
               ip = Convert.ToString(System.Web.HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"]);
           if (string.IsNullOrEmpty(ip))
               ip = Convert.ToString(System.Web.HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"]);
           return ip;
       }


官方微信
官方QQ群
31647020