首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >错误0x80005000和DirectoryServices

错误0x80005000和DirectoryServices
EN

Stack Overflow用户
提问于 2009-11-12 22:03:58
回答 13查看 125.4K关注 0票数 51

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

代码语言:javascript
复制
    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();

我得到了以下异常:

代码语言:javascript
复制
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()

作为控制台应用程序中的一个代码片段,这是可行的。但当我将其作为WCF服务的一部分运行时(使用相同的凭据运行),它会抛出上述异常。

有什么建议吗?

谢谢

EN

回答 13

Stack Overflow用户

回答已采纳

发布于 2009-11-12 22:07:32

这是一个权限问题。

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

WCF服务在哪里运行?在IIS中?最有可能的情况是,它在一个单独的帐户下运行,该帐户不允许查询Active Directory。

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

代码语言:javascript
复制
DirectoryEntry directoryEntry = 
    new DirectoryEntry("LDAP://someserver.contoso.com/DC=contoso,DC=com", 
                       userName, password);

好吧,所以说到底可能不是凭据的问题(我看到的80%以上的情况通常都是这样)。

稍微修改一下你的代码怎么样?

代码语言:javascript
复制
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];
   }
}

我的想法是:为什么不直接告诉DirectorySearcher你对什么属性感兴趣呢?然后你不需要做额外的步骤来从搜索结果中获得完整的DirectoryEntry (应该更快),既然你告诉目录搜索器找到那个属性,它肯定会被加载到搜索结果中-所以除非它是null (没有设置值),否则你应该能够很容易地检索到它。

Marc

票数 36
EN

Stack Overflow用户

发布于 2012-04-11 14:55:45

我做了一次又一次同样的事情,但似乎没有任何帮助。

将路径从ldap://更改为LDAP://确实起到了作用。

票数 125
EN

Stack Overflow用户

发布于 2014-07-01 09:02:29

在Ektron的环境下,这个问题可以通过在IIS6中安装“Windows元数据库兼容性”功能来解决:

对于Windows元数据库兼容性,请检查“

功能”或“角色服务”,如果缺少,请添加:

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

票数 22
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/1722398

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档