UserPrincipal GetUnderlyingObject:缺少属性

Dän*_*änu 4 c# active-directory principal

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

DirectoryEntry directoryEntry = principal.GetUnderlyingObject() as DirectoryEntry;
Run Code Online (Sandbox Code Playgroud)

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

directoryEntry.Properties.Contains("physicalDeliveryOfficeName");
Run Code Online (Sandbox Code Playgroud)

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

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

谢谢你的回答!

Avn*_*tan 6

访问DirectoryEntry的所有字段是一个可能缓慢而繁重的操作.某些字段可能无法复制到所有域控制器,因此引入这些值可能需要访问远程且访问速度较慢的全局编录(GC)服务器.

一旦掌握了DirectoryEntry并且想要提取特定值,就可以调用该RefreshCache方法,并为其传递所需属性的名称.