WCF取得访问端的IP地址

 [OperationContract]

 public string GetCustomerIP()
 {
      string CustomerIP = "";
    
     if( HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"] != null)
          CustomerIP = HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"].ToString();
       else if (HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"] != null)                
           CustomerIP = HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"].ToString();
      return CustomerIP;
  }

你可能感兴趣的:(IP地址)