6

我正在尝试physicalDeliveryOfficeNameDirectoryEntry由 UserPrincipal 实例的 GetUnderlyingObject 方法返回的属性加载:

DirectoryEntry directoryEntry = principal.GetUnderlyingObject() as DirectoryEntry;

这意味着以下语句返回 false:

directoryEntry.Properties.Contains("physicalDeliveryOfficeName");

StringCollection DirectorySearcher.PropertiesToLoad我知道可以通过在使用 said 时添加名称来加载此属性DirectorySearcher

我的问题是,为什么DirectoryEntry方法返回的不GetUnderlyingObject包含所有属性?以及如何在不使用的情况下加载此属性DirectorySearcher

4

2 回答 2

7

Accessing all fields for a DirectoryEntry is a potentially slow and heavy operation. Some fields might not be replicated to all domain controllers, and so bringing the values might require accessing a remote and slow-to-access Global Catalog (GC) server.

Once you have a DirectoryEntry in hand and you want to pull a specific value, you can call the RefreshCache method, passing it the names of the properties you need.

于 2012-02-22T20:58:23.253 回答
0

使用RefreshCache

        UserPrincipal up = ...
        using (DirectoryEntry de = up.GetUnderlyingObject() as DirectoryEntry)
        {
            foreach (var name in de.Properties.PropertyNames)
            {
                Console.WriteLine(name);
            }
            Console.WriteLine();

            // The canonicalName attribute is operational (also called constructed). 
            // Active Directory does not actually save the value, but calculates it on demand. This is probably the issue. In ADSI we use the GetInfoEx

            de.RefreshCache(new string[] { "canonicalName" });
            var canonicalName = de.Properties["canonicalName"].Value as string;
        }

属性名称:

objectClass
cn
sn
givenName
distinguishedName
instanceType
whenCreated
whenChanged
displayName
uSNCreated
memberOf
uSNChanged
nTSecurityDescriptor
name
objectGUID
userAccountControl
badPwdCount
codePage
countryCode
badPasswordTime
lastLogoff
lastLogon
pwdLastSet
primaryGroupID
objectSid
accountExpires
logonCount
sAMAccountName
sAMAccountType
userPrincipalName
objectCategory
dSCorePropagationData
lastLogonTimestamp

缺少canonicalName属性。

于 2019-06-05T09:29:40.320 回答