从活动目录中读取所有用户数据时出现以下错误 [英] Below error is coming while reading the all the users data from the active directory
问题描述
Quote:System.Runtime.InteropServices.COMException(0x8007203B):发生了本地错误。
在System.DirectoryServices.SearchResultCollection.ResultsEnumerator.MoveNext()
at System.DirectoryServices.AccountManagement.ADEntriesSet.MoveNext()
在System.DirectoryServices.AccountManagement.FindResultEnumerator`1.MoveNext()
$ / b $ b $在System.DirectoryServices.AccountManagement.FindResultEnumerator`1.System.Collections.IEnumerator.MoveNext()
在LaunchPad2.CustomerMasterData .GetPhoneNumbersFromActiveDirectory()
我尝试过:
$ 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():);
}
}
}
}
听起来您的代码在没有访问example.com域名权限的帐户下运行。
尝试在PrincipalContext
构造函数中传递该域的有效凭据:
使用( var context = new PrincipalContext(ContextType.Domain, example.com, @ domain\username, password))
{
...
}
Quote:System.Runtime.InteropServices.COMException (0x8007203B): A local error has occurred.
at System.DirectoryServices.SearchResultCollection.ResultsEnumerator.MoveNext()
at System.DirectoryServices.AccountManagement.ADEntriesSet.MoveNext()
at System.DirectoryServices.AccountManagement.FindResultEnumerator`1.MoveNext()
at System.DirectoryServices.AccountManagement.FindResultEnumerator`1.System.Collections.IEnumerator.MoveNext()
at LaunchPad2.CustomerMasterData.GetPhoneNumbersFromActiveDirectory()
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() : ""); } } } }
Sounds like your code is running under an account which doesn't have permission to access the "example.com" domain.
Try passing valid credentials for that domain in thePrincipalContext
constructor:
using (var context = new PrincipalContext(ContextType.Domain, "example.com", @"domain\username", "password")) { ... }
这篇关于从活动目录中读取所有用户数据时出现以下错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!