6

UserPrincipalインスタンスのGetUnderlyingObjectメソッドによって返される属性physicalDeliveryOfficeNameをロードしようとしています。DirectoryEntry

DirectoryEntry directoryEntry = principal.GetUnderlyingObject() as DirectoryEntry;

これは、次のステートメントがfalseを返すことを意味します。

directoryEntry.Properties.Contains("physicalDeliveryOfficeName");

StringCollection DirectorySearcher.PropertiesToLoadこのプロパティは、上記を使用するときにに名前を追加することでロードできることを知っていますDirectorySearcher

DirectoryEntry私の質問は、メソッドによって返されるものGetUnderlyingObjectにすべてのプロパティが含まれていないのはなぜですか?そして、どうすればこのプロパティを使用せずにロードできますDirectorySearcherか?

4

2 に答える 2

7

DirectoryEntryのすべてのフィールドにアクセスすることは、遅くて重い操作になる可能性があります。一部のフィールドはすべてのドメインコントローラーに複製されない場合があるため、値を取得するには、リモートでアクセスが遅いグローバルカタログ(GC)サーバーにアクセスする必要がある場合があります。

DirectoryEntryが手元にあり、特定の値を取得する場合は、RefreshCacheメソッドを呼び出して、必要なプロパティの名前を渡すことができます。

于 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;
        }

PropertyNames

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 に答える