asp.net獲取訪問者ip地址的函數

/// <summary>  
/// 獲取IP地址  
/// </summary>  
     public static string IPAddress  
     {  
         get  
         {  
             string userIP;  
             // HttpRequest Request = HttpContext.Current.Request;  
             HttpRequest Request = HttpContext.Current.Request; // ForumContext.Current.Context.Request;  
             // 若是使用代理,獲取真實IP  
             if (Request.ServerVariables["HTTP_X_FORWARDED_FOR"] != "")  
                 userIP = Request.ServerVariables["REMOTE_ADDR"];  
             else  
                 userIP = Request.ServerVariables["HTTP_X_FORWARDED_FOR"];  
             if (userIP == null || userIP == "")  
                 userIP = Request.UserHostAddress;  
             return userIP;  
         }  
     } 
相關文章
相關標籤/搜索