本文介绍了从活动目录中读取所有用户数据时出现以下错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我尝试过:
$ b使用(var context = new PrincipalContext(ContextType.Domain,example.com))
{
using(var searcher = new PrincipalSearcher(new Use rPrincipal(context)))
{
PrincipalSearchResult< Principal> searchResult = searcher.FindAll();
foreach(searchResult中的主要结果)
{
DirectoryEntry sr = result.GetUnderlyingObject()as DirectoryEntry;
if(sr.Properties.Contains(mobile)&& sr.Properties.Contains(sAMAccountName))
{
dctUserDetails.Add(sr.Properties [sAMAccountName] [0] .ToString()。ToLower(),
sr.Properties [mobile] [0] .ToString()。ToUpper()!=NA?sr.Properties [mobile] [0] .ToString():);
}
}
}
}
解决方案
What I have tried:
using (var context = new PrincipalContext(ContextType.Domain, "example.com")) { using (var searcher = new PrincipalSearcher(new UserPrincipal(context))) { PrincipalSearchResult<Principal> searchResult = searcher.FindAll(); foreach (Principal result in searchResult) { DirectoryEntry sr = result.GetUnderlyingObject() as DirectoryEntry; if (sr.Properties.Contains("mobile") && sr.Properties.Contains("sAMAccountName")) { dctUserDetails.Add(sr.Properties["sAMAccountName"][0].ToString().ToLower(), sr.Properties["mobile"][0].ToString().ToUpper() != "NA" ? sr.Properties["mobile"][0].ToString() : ""); } } } }
解决方案
这篇关于从活动目录中读取所有用户数据时出现以下错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!