简体   繁体   中英

C# Active Directory DirSync. Is it possible to get distinguished name attribute?

I have a code that gives me a list of Users changed in Active Directory. It uses DirSync Control. When I choose to get the full list of attributes I receive only the following:

objectclass: top
objectclass: person
objectclass: organizationalPerson
objectclass: user
whencreated: 20141202165637.0Z
name: gfdgfgfd
objectsid: System.Byte[]
countrycode: 0
primarygroupid: 513
samaccounttype: 805306368
useraccountcontrol: 66048
pwdlastset: 130620129983259471
parentguid: System.Byte[]
codepage: 0
objectcategory: CN=Person,CN=Schema,CN=Configuration,DC=test,DC=com
userprincipalname: gfdgdf@test.com
displayname: gfdgfgfd
accountexpires: 9223372036854775807
ntsecuritydescriptor: System.Byte[]
givenname: gfdgfgfd
instancetype: 4
samaccountname: gfdgdf
objectguid: System.Byte[]

I need to get also the distinguished name. Is it possible

This is my code:

string str_dcName = "xxxxxxxx";
System.DirectoryServices.DirectoryEntry rootDSE = new System.DirectoryServices.DirectoryEntry("LDAP://rootDSE");
System.Net.NetworkCredential cr = new System.Net.NetworkCredential(@"User", "Pass", "test.com");
LdapConnection connection = new LdapConnection(str_dcName);
connection.Credential = cr;
connection.Bind();

SearchRequest request = new SearchRequest("DC=test,DC=com", "(|(objectClass=organizationalUnit)(isDeleted=TRUE)(objectClass=user)(objectcategory=person))", SearchScope.Subtree, null);

DirSyncRequestControl dirSyncRC = new DirSyncRequestControl(cookie, DirectorySynchronizationOptions.IncrementalValues, Int32.MaxValue);
request.Controls.Add(dirSyncRC);

bool bMoreData = true;
SearchResponse searchResponse = (SearchResponse)connection.SendRequest(request);

Thanks!

OK, after a while I discovered that I was missing something. In SearchResponse all the entries have:

  • attributes
  • controls
  • distinguished name

So Distinguished name is not inside of the attributes.

while (bMoreData)
   foreach (SearchResultEntry entry in searchResponse.Entries)
      Console.WriteLine(entry.DistinguishedName);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM