Exemplo n.º 1
0
 private void LoadBaseDNData()
 {
     using (LdapConnHelper ldapConn = new LdapConnHelper(DomainName, LdapConnHelper.DefaultLdapPortNum, true, false))
     {
         ldapConn.TryConnection(new TimeSpan(0, 1, 0), CredentialCache.DefaultNetworkCredentials, 3, AuthType.Basic);
         if (ldapConn.IsConnected)
         {
             WriteTrace("Connected to: " + DomainName);
         }
         LdapFilter        ldapFilter = new LdapFilter(LdapFilter.AllObjects);
         LdapSearchRequest searchReq  = new LdapSearchRequest(RootOU, ldapFilter,
                                                              System.DirectoryServices.Protocols.SearchScope.OneLevel, null);
         SearchResponse searchResp = ldapConn.PerformSearch(searchReq);
         foreach (SearchResultEntry sre in searchResp.Entries)
         {
             DdBaseDN.Items.Add(sre.DistinguishedName);
         }
     }
 }
Exemplo n.º 2
0
 private void BtnSearch_Click(object sender, EventArgs e)
 {
     using (LdapConnHelper ldapConn = new LdapConnHelper(DomainName, LdapConnHelper.DefaultLdapPortNum, true, false))
     {
         ldapConn.TryConnection(new TimeSpan(0, 1, 0), CredentialCache.DefaultNetworkCredentials, 3, AuthType.Basic);
         if (ldapConn.IsConnected)
         {
             WriteTrace("Connected to: " + DomainName);
         }
         LdapFilter        ldapFilter = new LdapFilter(TxtSearchFilter.Text.Trim());
         LdapSearchRequest searchReq  = new LdapSearchRequest(DdBaseDN.Text, ldapFilter,
                                                              System.DirectoryServices.Protocols.SearchScope.Subtree, LdapSearchRequest.UserAttributes);
         SearchResponse searchResp = ldapConn.PerformSearch(searchReq);
         foreach (SearchResultEntry sre in searchResp.Entries)
         {
             LdapUserRecord usrRecord = new LdapUserRecord(sre);
             if (usrRecord.IsValidUser())
             {
                 WriteTrace(usrRecord.ToString());
             }
         }
     }
 }