C# 通过具有管理员凭据的C代码访问某些属性时发生LDAP错误(0x8000500c)
我正在尝试使用C#和.NET库“System.DirectoryServices”从LDAP(而不是AD)条目中读取属性 我的LDAP条目如下所示:C# 通过具有管理员凭据的C代码访问某些属性时发生LDAP错误(0x8000500c),c#,.net,ldap,directoryservices,C#,.net,Ldap,Directoryservices,我正在尝试使用C#和.NET库“System.DirectoryServices”从LDAP(而不是AD)条目中读取属性 我的LDAP条目如下所示: dn: uid=foo,ou=People,dc=companyname,dc=local objectClass: posixAccount objectClass: top objectClass: inetOrgPerson objectClass: organizationalPerson objectClass: person gidNu
dn: uid=foo,ou=People,dc=companyname,dc=local
objectClass: posixAccount
objectClass: top
objectClass: inetOrgPerson
objectClass: organizationalPerson
objectClass: person
gidNumber: 0
givenName: Foo
sn: Bar
displayName: Foo Bar
uid: foo
homeDirectory: /
cn: foo bar
uidNumber: 9846
userPassword: {SHA}Ys23Ag/5IOWqZCw9QGaVDdHwH00=
mail: foo@dodo.net
我使用的Linux LDAP服务器是“389”,也称为“Fedora目录服务器”。我的C#代码如下所示:
string value = null;
DirectoryEntry ouEntry = null;
string path = "LDAP://192.168.150.192/ou=People, dc=companyname, dc=local";
string adminUserName = "cn=Directory Manager";
string adminPassword = "supersecureadminpassword";
ouEntry = new DirectoryEntry(path, adminUserName, adminPassword, AuthenticationTypes.None);
DirectorySearcher searcher = new DirectorySearcher(ouEntry, "uid=foo");
SearchResult result = searcher.FindOne();
DirectoryEntry userEntry = result.GetDirectoryEntry();
var props = userEntry.Properties.PropertyNames;
if(userEntry.Properties.Contains("givenName"))
value = userEntry.Properties["givenName"].Value.ToString();
代码运行得非常好。但是,如果我将“givenName”替换为“displayName”,代码将在if(userEntry.Properties.Contains(“displayName”)
行失败,并使用System.Runtime.InteropServices.com异常:未知错误(0x8000500c)
。
即使在检查属性列表props
时显示属性“displayName”,也会出现这种情况
我读过,因为这似乎是一个类似的问题。但是,我不知道如何解决这个问题,因为我只有一个静态IP地址,而不是LDAP服务器的完全限定名称
有人知道我代码中的问题是什么吗?是否与所提到的帖子有关?我该如何解决这个问题
先谢谢你
更新1:
我还尝试用LDAP服务器的Linux主机名(shell命令hostname
的输出)替换IP地址,但也没有成功。而且,据我所知,“displayName”不是一个自定义属性。因此,我的问题可能与链接帖子中的问题不匹配。
我真的很绝望,不知道该怎么办。任何帮助都将不胜感激。几件事:
DirectorySearcher searcher = new DirectorySearcher(ouEntry, ...);
searcher.PropertiesToLoad.Add("displayName");
尽管您说它适用于“givenName”,但您可能会尝试测试第三方工具,以检查您的连接是否没有问题。例如,您可以尝试,尝试提供相同的连接数据,并搜索您的筛选器字符串,看看它是否返回所有必需的数据。谢谢您的回答。参考你的建议:1)你确定吗?它不应该是LDAP可分辨名称吗?否则,您将如何区分不同OU的用户?无论如何,即使我用
“目录管理器”
替换“cn=Directory Manager”
,我仍然会在同一行得到相同的错误。2)好的,但无论如何它都应该工作,对吗?3.)这是正确的财产。我还将其用作LDAP浏览器,并检查了所有属性。4.)我以前也试过,没什么区别。你还有别的想法吗?谢谢你的帮助。对不起,我看到你说,这是LDAP而不是广告。在这种情况下,你是对的,它可能是CN=。。。然而,奇怪的是,当您在没有CN=-的情况下更改“目录管理器”时,它并没有更改其输出,所以看起来这就是问题所在。尝试指定“abc”而不是真正的密码-我相信你会得到同样的结果。您是否尝试过AuthenticationType以外的其他方法。无?