【发布时间】:2014-07-26 16:52:39
【问题描述】:
我正在尝试使用 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
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 Directory Server”。我的 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.COMException: Unknown error (0x8000500c)。
即使在检查属性列表props 时出现了属性“displayName”,也会发生这种情况。
我读过this post,因为它似乎是一个类似的问题。但是,我不知道如何解决这个问题,因为我只有一个静态 IP 地址,而不是我的 LDAP 服务器的完全限定名称。
有没有人知道我的代码中的问题是什么以及它是否与提到的帖子有关?我该如何解决这个问题?
非常感谢。
更新 1:
我还尝试用 LDAP 服务器的 Linux 主机名(shell 命令hostname 的输出)替换 IP 地址,但这也不起作用。此外,据我所知,“displayName”不是自定义属性。因此,我的问题可能与链接帖子中的问题不匹配。
我真的很绝望,不知道该怎么办。任何帮助将不胜感激。
【问题讨论】:
标签: c# .net ldap directoryservices