2012-07-24 37 views
0

我編寫了一個從Active Directory獲取數據的程序,我需要一個將數據過濾爲l(城市)參數的LDAP過濾器。如何創建一個具有城市(「l」)的LDAP過濾器參數

我的代碼:

public void SearchByCity(string city) 
     { 
                 //What I must do :(
      DirectoryEntry Entry = new DirectoryEntry("LDAP://<l= + city + >"); 
      string filter = "(&(objectClass=user)(objectCategory=person)(cn=*))"; 
      DirectorySearcher Searcher = new DirectorySearcher(Entry, filter); 

      var q = from s in Searcher.FindAll().OfType<SearchResult>() 
        select new 
        { 
         Benutzer = GetProperty(s, "sAMAccountName"), 
         eMail = GetProperty(s, "mail"), 
         Vorname = GetProperty(s, "givenName"), 
         Nachname = GetProperty(s, "sn"), 
         Telefon = GetProperty(s, "telephoneNumber"), 
         UserID = s.GetDirectoryEntry().Guid 
        }; 

      this.myListView.DataSource = q; 
      this.myListView.DataBind(); 
     } 

塔拉索夫

+0

'I'或'l'(區域)? – 2012-07-24 14:26:52

+0

nope l在LDAP過濾器中的城市,但我現在有一個解決方案...我發佈它 – Tarasov 2012-07-24 19:51:41

+0

string filter =「(&(objectClass = user)(objectCategory = person)(l =」+ city +「)(cn = *))「; // city是LDAP參數值 – Tarasov 2012-07-24 19:53:05

回答

0

的孤子:

public void SearchByPlace(string city) 
     { 
      DirectoryEntry Entry = new DirectoryEntry("LDAP://" + Properties.Settings.Default.Domain); 
      string filter = "(&(objectClass=user)(objectCategory=person)(l=" + city + ")(cn=*))"; 
      DirectorySearcher Searcher = new DirectorySearcher(Entry, filter); 

      var q = from s in Searcher.FindAll().OfType<SearchResult>() 
        select new 
        { 
         Benutzer = GetProperty(s, "sAMAccountName"), 
         eMail = GetProperty(s, "mail"), 
         Vorname = GetProperty(s, "givenName"), 
         Nachname = GetProperty(s, "sn"), 
         Telefon = GetProperty(s, "telephoneNumber"), 
         UserID = s.GetDirectoryEntry().Guid 
        }; 

      this.myListView.DataSource = q; 
      this.myListView.DataBind(); 
     } 
0

使用此過濾器

(&(objectCategory=person)(objectClass=user)(!sAMAccountType=805306370)(l=yourcity))