Asp.net 获取访问者IP

using System.Web;

namespace Wxlhjcyy.Public
{
    public class GetIp
    {
        public static string IPAddress
        {
            get
            {
                string userIP;
                HttpRequest Request = HttpContext.Current.Request; // ForumContext.Current.Context.Request; 
                                                                   // 如果使用代理,获取真实IP 
                userIP = Request.UserHostAddress;

                if (string.IsNullOrEmpty(userIP))
                {

                    if (Request.ServerVariables["HTTP_X_FORWARDED_FOR"] != "")
                        userIP = Request.ServerVariables["REMOTE_ADDR"];
                    else
                        userIP = Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
                }
                return userIP;
            }
        }
    }
}

  

  

posted @ 2018-11-27 11:06  这座城市那么空  阅读(1856)  评论(0编辑  收藏  举报