当我尝试从活动目录中检索“AccountExpirationDate”时,出现了一个奇怪的问题。
我使用以下代码来检索用户:
DirectoryEntry dirEntry = new DirectoryEntry(Path);
DirectorySearcher search = new DirectorySearcher(dirEntry);
// specify the search filter
search.Filter = "(&(objectClass=user)(mail=" + email + "))";
// perform the search
SearchResult result = search.FindOne();
DirectoryEntry user = result.GetDirectoryEntry();
接下来,我会检索“AccountExpirationDate”:
object o1 = user.Properties["accountExpires"].Value; //return a COM object and I cannot retrieve anything from it
object o2 = user.Properties["AccountExpirationDate"].Value; //return null
object o3 = user.InvokeGet("AccountExpirationDate"); //return the DateTime
我想知道这里发生了什么? 为什么我无法使用DirectoryEntry.Properties来检索AccountExpirationDate? DirectoryEntry.Properties和DirectoryEntry.InvokeGet有何不同?
非常感谢。