Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# DirectorySearcher出现间歇性转介错误_C#_.net_Active Directory_Ldap_Directorysearcher - Fatal编程技术网

C# DirectorySearcher出现间歇性转介错误

C# DirectorySearcher出现间歇性转介错误,c#,.net,active-directory,ldap,directorysearcher,C#,.net,Active Directory,Ldap,Directorysearcher,我正在使用DirectorySearcher根据电子邮件地址查找用户帐户: using (var searcher = new DirectorySearcher { SearchRoot = new DirectoryEntry($"LDAP://DC={companyOfficeLocation},DC={companyDomain},DC=com"), SearchScope = SearchScope.Subtree, Filter = $"(mail={emai

我正在使用
DirectorySearcher
根据电子邮件地址查找用户帐户:

using (var searcher = new DirectorySearcher
{
    SearchRoot = new DirectoryEntry($"LDAP://DC={companyOfficeLocation},DC={companyDomain},DC=com"),
    SearchScope = SearchScope.Subtree,
    Filter = $"(mail={email})",
    PropertiesToLoad = { "sAMAccountName" },
    ReferralChasing = ReferralChasingOption.All,
})
{
    return searcher.FindAll().Cast<SearchResult>()
        .Select(r => (string)r.Properties["sAMAccountName"][0])
        .ToList();
}
使用(var searcher=newdirectorysearcher
{
SearchRoot=new DirectoryEntry($“LDAP://DC={companyOfficeLocation},DC={companyDomain},DC=com”),
SearchScope=SearchScope.Subtree,
筛选器=$“(邮件={email})”,
PropertiesToLoad={“sAMAccountName”},
ReferralChasing=ReferralChasingOption.All,
})
{
返回searcher.FindAll().Cast()
.Select(r=>(字符串)r.Properties[“sAMAccountName”][0])
.ToList();
}
此代码在
System.DirectoryServices.directoryservicescomeexception
中间歇性失败,并显示错误消息
服务器返回了一个引用。

这些错误在不同的机器上是不一致的(例如,在不同的web服务器上,同一个查询可能在同一时间段内失败或成功)。有迹象表明,ActiveDirectory服务器重新启动或web服务器重新启动可能会触发错误

我想知道:转诊错误的可能原因是什么?为什么即使将
ReferralChasing
属性设置为
All
,我仍会看到引用错误

编辑:

从DirectoryServicesCOMException的
ExtendedErrorMessage
属性捕获的更多信息:

0000202B:参考:DSID-031007F3,数据0,1接入点参考1:'arlington.predictivetechnologies.com'


请指定在DirectoryEntry中传递的确切LDAP路径constructor@oldovets我加入了一个更完整的LDAP路径,显示了完整的结构。我已经填写了特定组织的实际域部分值。请看@oldovets,谢谢你指出这篇文章。阅读之后,似乎有很多事情可能导致这种情况;是否有一个答案与我的实例相关?在无服务器绑定的情况下,“将使用来自调用线程的安全上下文所在域的默认域控制器”。即。它取决于运行进程/线程的用户。当我的程序试图不连接到LDAP字符串中指定的域(使用无服务器绑定)时,我在使用线程模拟时遇到了无服务器绑定的问题。最好指定域或域控制器,而不要依赖于运行当前进程的用户。