C#Active Directory DirSync。是否有可能获得专有名称属性?

时间:2014-12-02 17:43:51

标签: c# active-directory

我有一个代码,它给我一个在Active Directory中更改的用户列表。它使用DirSync控件。当我选择获取完整的属性列表时,我只收到以下内容:

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[]

我还要得到尊贵的名字。是否可能

这是我的代码:

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);

谢谢!

1 个答案:

答案 0 :(得分:2)

好吧,过了一会儿,我发现我错过了什么。 在SearchResponse中,所有条目都包含:

  • 属性
  • 对照
  • 专有名称

所以杰出的名字不在属性之内。

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