2013-09-06 24 views

cevap

17

:

DirectoryEntry adEntry = null; 

    private void SetADInfoAndCredentials() 
    { 
     adEntry = new DirectoryEntry("LDAP://" + ad_textBox.Text); 
     adEntry.Username = user_textBox.Text; 
     adEntry.Password = pw_textBox.Text; 
    } 

    private void SearchForMailInAD() 
    { 
     DirectorySearcher adSearcher = new DirectorySearcher(adEntry); 
     adSearcher.Filter = ("mail=" + mail_textBox.Text); 
     SearchResultCollection coll = adSearcher.FindAll(); 
     foreach (SearchResult item in coll) 
     { 
      foundUsers_listBox.Items.Add(item.GetDirectoryEntry()); 
     } 
    } 

€: Bu

public static SearchResultCollection FindAccountByEmail(string pEmailAddress) 
    { 
     string filter = string.Format("(proxyaddresses=SMTP:{0})", email); 

     using (DirectoryEntry gc = new DirectoryEntry("LDAP:")) 
     { 
      foreach (DirectoryEntry z in gc.Children) 
      { 
       using (DirectoryEntry root = z) 
       { 
        using (DirectorySearcher searcher = new DirectorySearcher(root, filter, new string[] { "proxyAddresses", "objectGuid", "displayName", "distinguishedName" })) 
        { 
         searcher.ReferralChasing = ReferralChasingOption.All; 
         SearchResultCollection result = searcher.FindAll(); 

         return result; 
        } 
       } 
      } 
     } 
     return null; 
    } 
+0

teşekkür ederiz tüm posta adreslerini barındıran proxyAddresses posta adresine arayacaktır - İkinci kod seti inşaat büyük . İlk (LDAP) yaklaşımı ne zaman kullanmak isterim? Ve LDAP'den sonra neler oluyor: //? –

+0

İlk kod, yalnızca hangi birincil posta adresinin tanımlandığını tam olarak bilmek için çalışır. Ldap'tan sonra alanınızı veya kontrol cihazınızı ayarlayabilir –