问题
When using the FindAll() method of the DirectorySearcher in .net, does the GetDirectoryEntry() method of the SearchResultCollection require another trip to Active Directory? e.g....
Dim src As SearchResultCollection
Dim ds As New DirectorySearcher
' code to setup DirectorySearcher
' go to Active Directory and fill collection with results
src = ds.FindAll()
'...later on in code or whatever
' does the next line of code require another trip to Active Directory?
Dim de As DirectoryEntry = src.item(0).GetDirectoryEntry()
回答1:
According to the documentation it will requery AD to get the directory entry.
Reference
Use GetDirectoryEntry when you want to look at the live entry instead of the entry that was returned through DirectorySearcher, or when you want to invoke a method on the object that was returned.
Note: Calling GetDirectoryEntry on each SearchResult returned through DirectorySearcher can be slow.
回答2:
Yes, it will go back to AD and get the whole DirectoryEntry object.
If you want to avoid this (and you should, whenever possible), specify those properties you really need on your DirectorySearcher
using the PropertiesToLoad
collection, and then inspect the SearchResult.Properties
for those values - those will be returned with the search and do not require yet another roundtrip to the Active Directory.
Marc
来源:https://stackoverflow.com/questions/1135155/does-searchresultcollections-getdirectoryentry-have-to-query-activedirectory-ag