2012-02-22 40 views
4

我試圖從由UserPrincipal實例的GetUnderlyingObject方法返回一個DirectoryEntry加載屬性physicalDeliveryOfficeNameUserPrincipal GetUnderlyingObject:屬性中沒有

DirectoryEntry directoryEntry = principal.GetUnderlyingObject() as DirectoryEntry; 

這意味着下面的語句返回false:

directoryEntry.Properties.Contains("physicalDeliveryOfficeName"); 

我知道,使用上述DirectorySearcher時,可以通過將名稱添加到StringCollectionDirectorySearcher.PropertiesToLoad加載此屬性。

我的問題是,爲什麼GetUnderlyingObject方法返回的DirectoryEntry包含所有屬性?我怎樣才能加載這個屬性,而不使用DirectorySearcher

謝謝你的回答!

回答

5

訪問DirectoryEntry的所有字段是一個潛在的緩慢和沉重的操作。有些字段可能不會被複制到所有域控制器,因此帶這些值可能需要訪問遠程和訪問速度慢的全局編錄(GC)服務器。

一旦手中有DirectoryEntry並且想要拉取特定值,您可以調用RefreshCache方法,並將它傳遞給您需要的屬性的名稱。