错误0x80005000和DirectoryServices

God*_*ter 40 .net c# wcf directoryservices active-directory

我正在尝试使用.Net中的目录服务运行简单的LDAP查询.

    DirectoryEntry directoryEntry = new DirectoryEntry("LDAP://someserver.contoso.com/DC=contoso,DC=com");
    directoryEntry.AuthenticationType = AuthenticationTypes.Secure;

    DirectorySearcher directorySearcher = new DirectorySearcher(directoryEntry);

    directorySearcher.Filter = string.Format("(&(objectClass=user)(objectCategory=user) (sAMAccountName={0}))", username);

    var result = directorySearcher.FindOne();
    var resultDirectoryEntry = result.GetDirectoryEntry();

    return resultDirectoryEntry.Properties["msRTCSIP-PrimaryUserAddress"].Value.ToString();
Run Code Online (Sandbox Code Playgroud)

我得到以下例外:

System.Runtime.InteropServices.COMException (0x80005000): Unknown error (0x80005000)
  at System.DirectoryServices.DirectoryEntry.Bind(Boolean throwIfFail)
  at System.DirectoryServices.DirectoryEntry.Bind()
  at System.DirectoryServices.DirectoryEntry.get_AdsObject()
  at System.DirectoryServices.DirectorySearcher.FindAll(Boolean findMoreThanOne)
  at System.DirectoryServices.DirectorySearcher.FindOne()
Run Code Online (Sandbox Code Playgroud)

作为控制台应用中的代码段,这是有效的.但是,当我将其作为WCF服务的一部分运行(在相同的凭据下运行)时,它会抛出上述异常.

有什么建议?

谢谢

小智 99

我一次又一次地拥有同样的东西,似乎没有任何帮助.

从改变路径ldap://,以LDAP://确实的伎俩.

  • 这也为我修好了.LDAP必须是大写的. (12认同)
  • WAAAAAAAAT ??!我花了2个小时在这个LDAP上解决了我的问题! (12认同)

mar*_*c_s 31

这是一个许可问题.

当您运行控制台应用程序时,该应用程序将使用您的凭据运行,例如"您".

WCF服务运行在哪里?在IIS?最有可能的是,它在一个单独的帐户下运行,该帐户无权查询Active Directory.

您可以尝试使WCF模拟工作正常工作,以便传递您自己的凭据,或者您可以在创建DirectoryEntry时指定用户名/密码:

DirectoryEntry directoryEntry = 
    new DirectoryEntry("LDAP://someserver.contoso.com/DC=contoso,DC=com", 
                       userName, password);
Run Code Online (Sandbox Code Playgroud)

好的,所以它可能不是凭证(在我看到的80%以上的情况下通常就是这种情况).

如何更改代码呢?

DirectorySearcher directorySearcher = new DirectorySearcher(directoryEntry);
directorySearcher.Filter = string.Format("(&(objectClass=user)(objectCategory=user) (sAMAccountName={0}))", username);

directorySearcher.PropertiesToLoad.Add("msRTCSIP-PrimaryUserAddress");

var result = directorySearcher.FindOne();

if(result != null)
{
   if(result.Properties["msRTCSIP-PrimaryUserAddress"] != null)
   {
      var resultValue = result.Properties["msRTCSIP-PrimaryUserAddress"][0];
   }
}
Run Code Online (Sandbox Code Playgroud)

我的想法是:为什么不直接告诉DirectorySearcher你对你感兴趣的属性是什么?然后你不需要再做一个额外的步骤来DirectoryEntry从搜索结果中获取全部内容(应该更快),并且由于你告诉目录搜索者找到该属性,它肯定会被加载到搜索结果中 - 所以除非它是null(没有设置值),那么你应该能够轻松地检索它.

  • 0x80005000是一个非常"样板"的错误,几乎可以说是...... (3认同)

Dav*_*tas 19

在Ektron的上下文中,通过在Windows中安装"IIS6元数据库兼容性"功能解决了此问题:

检查IIS6元数据库兼容性的"Windows功能"或"角色服务",如果缺少则添加:

在此输入图像描述

参考:https://portal.ektron.com/KB/1088/

  • 对于我的具体问题(遇到 OP 错误,但我要使用 IIS,而不是 LDAP),这解决了它。谢谢 (3认同)

pg0*_*0xC 11

我有同样的错误 - 在我的情况下,它是路径参数中的额外斜杠,这有所不同.

坏:

DirectoryEntry directoryEntry = 
    new DirectoryEntry("LDAP://someserver.contoso.com/DC=contoso,DC=com/", 
                       userName, password);
Run Code Online (Sandbox Code Playgroud)

好:

DirectoryEntry directoryEntry = 
    new DirectoryEntry("LDAP://someserver.contoso.com/DC=contoso,DC=com", 
                       userName, password);
Run Code Online (Sandbox Code Playgroud)


Nic*_*byn 8

我也有这个错误,对我来说,它是名为"文件/文件夹访问组"的正斜杠的OU.

这个论坛帖子指出了我正确的方向.最后,.Replace("/","\\/")在使用前调用每个路径值为我解决了问题.


Ern*_*est 8

在IIS托管的站点上,尝试回收应用程序池。它解决了我的问题。谢谢

  • 如果您使用实际用户帐户作为应用程序池标识,而不是服务帐户:在应用程序池的高级设置中,将“加载用户配置文件”设置为 True。如果设置为 False,则当用户注销计算机时,COM 操作所需的注册表项将不可用。 (3认同)