C# System.DirectoryServices.DirectoryServicesCOMException(0x8007203B):发生本地错误

C# System.DirectoryServices.DirectoryServicesCOMException(0x8007203B):发生本地错误,c#,active-directory,directoryservices,C#,Active Directory,Directoryservices,当我们尝试在ActiveDirectory中搜索用户时,会出现异常-0x8007203B 基本上,我们部署了一个web服务,它使用DirectoryEntry&DirectorySearcher类在AD中查找用户,有时会发生这种异常。但是当我们做了IISReset,它又能正常工作了 代码非常简单,如下所示: DirectoryEntry domainUser = new DirectoryEntry("LDAP://xxx.yyy/dc=xxx,dc=yyy", "domain\user", "

当我们尝试在ActiveDirectory中搜索用户时,会出现异常-
0x8007203B

基本上,我们部署了一个web服务,它使用
DirectoryEntry
&
DirectorySearcher
类在AD中查找用户,有时会发生这种异常。但是当我们做了IISReset,它又能正常工作了

代码非常简单,如下所示:

DirectoryEntry domainUser = new DirectoryEntry("LDAP://xxx.yyy/dc=xxx,dc=yyy", "domain\user", "pwd", AuthenticationTypes.Secure); 
DirectoryEntry result = new DirectorySearcher(domainUser, filter);
只有在某些情况下才会发生这种情况。我没有太多的信息要提供,任何猜测都非常感谢

这就是我的过滤器的外观

public static string BuildFilter(DirectoryEntry dirEntry, string userName, string userMail)
{
   try
   {
      string filter = string.Empty;

      if (!string.IsNullOrEmpty(userName) && string.IsNullOrEmpty(userMail))
         filter = string.Format(@"(&(objectClass=user)(samaccounttype=805306368)(|(CN={0})(samaccountname={0})))", userName);
      else if (string.IsNullOrEmpty(userName) && !string.IsNullOrEmpty(userMail))
         filter = string.Format(@"(&(objectClass=user)(samaccounttype=805306368)(mail={0}))", userMail);
      else
         filter = string.Format(@"(&(objectClass=user)(samaccounttype=805306368)(|(CN={0})(samaccountname={0})(mail={1})))", userName, userMail);

      return filter;
   }
   catch (Exception ex)
   {
       _logger.Error("BuildUserSearch - Failed to build LDAP search", ex);
   }
   return null;
}

你猜得对吗

这是我的:

  • )
  • 让我困惑的是你说它大部分时间都有效

    这有用吗


    顺便说一句,如果我想到其他事情,我会更新。

    你说这只是一段时间后的附加信息。由于DirectoryEntry和DirectorySearcher是基于COM对象构建到一次性类中的,所以我首先要使用部分添加一些
    ,以确保底层对象被正确释放

    using(DirectoryEntry root = new DirectoryEntry(ldapPath))
    {
      using(DirectorySearcher searcher=new DirectorySearcher(root))
      {
        ...
      }
      ...
    }
    

    向我们展示如何设置您的
    DirectorySearcher
    !!你的
    过滤器是什么样子的??您还设置了哪些其他选项???@marc_,我已经添加了过滤代码,我无法访问他们的安全日志,但正如我所提到的,它可以工作,但有时会连续失败。但是IISReset使它再次工作。您使用的是什么版本的.NET framework??有两件事您可以尝试:(1)在筛选器中使用
    anr=
    搜索参数,或(2)移动到新的System.DirectoryServices.AccountManagement命名空间(需要.NET 3.5或更高版本),该命名空间更易于用于搜索-不确定是否会修复错误,不过:-(@marc_s,谢谢。我会试试accountmanagement。cedhost.com链接真的有用吗?他们不是每出现一个错误代码就抛出页面来销售注册表清理软件的网站之一吗?为什么页面上说我有这个错误?!谢谢,我的代码中缺少dispose,我现在就添加它,希望这就是原因。