【问题标题】:System.DirectoryServices.DirectoryServicesCOMException (0x8007203B): A local error has occurredSystem.DirectoryServices.DirectoryServicesCOMException (0x8007203B):发生本地错误
【发布时间】:2011-06-09 12:37:03
【问题描述】:

当我们尝试在 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;
}

【问题讨论】:

  • 告诉我们你做了什么来设置你的DirectorySearcher!!你的filter 是什么样的?您还设置了哪些其他选项??
  • @marc_s,我已经添加了过滤器代码,但我无法访问他们的安全日志,但正如我所提到的,它可以工作,但有时会连续失败。但是 IISReset 让它再次工作。
  • 您使用的是哪个版本的 .NET 框架?您可以尝试两件事:(1) 在过滤器中使用 anr= 搜索参数,或 (2) 移至更易于使用的新 System.DirectoryServices.AccountManagement 命名空间(需要 .NET 3.5 或更高版本)用于搜索 - 但不确定它是否会修复错误:-(
  • @marc_s,谢谢。我会试试 AccountManagement

标签: c# active-directory directoryservices


【解决方案1】:

你说这只是在一段时间后追加。由于 DirectoryEntry 和 DirectorySearcher 是建立在 COM 对象上的一次性类中,我首先只需添加一些 using 部分以确保正确释放底层对象。

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

【讨论】:

  • 谢谢,我的代码中缺少 dispose,我现在将添加它,希望这是原因。
【解决方案2】:

有任何猜测吗?

那么这是我的:

  1. ASP.NET: DirectoryServicesCOMException [...];
  2. Windows Error Codes: Repair 0x8007203B. How To Repair 0x8007203B

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

这有帮助吗?

附:如果我想到其他任何事情,我会更新。

【讨论】:

  • cedhost.com 链接真的有用吗?他们不是为每个错误代码抛出页面以销售注册表清理软件的网站之一吗?为什么页面说我有这个错误?!
猜你喜欢
  • 2012-11-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-06-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多