博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

WCF取得访问端的IP地址

Posted on 2010-09-15 15:32  小高好孩子  阅读(304)  评论(0)    收藏  举报

 [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;
  }