[英]LDAP error (0x8000500c) when accessing SOME attributes through C# code with administrator credentials
我正在嘗試使用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目錄服務器”。 我的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”,也會發生這種情況。
我已經閱讀了這篇文章 ,因為這似乎是一個類似的問題。 但是,我不知道如何解決該問題,因為我所擁有的只是一個靜態IP地址,而不是LDAP服務器的完全限定名稱。
有誰知道我的代碼中的問題是什么,如果與提到的帖子有關? 我該如何解決這個問題?
非常感謝。
更新1:我也嘗試用LDAP服務器的Linux主機名(shell命令hostname
的輸出)替換IP地址,但是那也不起作用。 而且,據我所知,“ displayName”不是自定義屬性。 因此,我的問題可能與鏈接文章中的問題不匹配。 我真的很絕望,不知道該怎么辦。 任何幫助將不勝感激。
一些事情:
嘗試使用PropertiesToLoad
DirectorySearcher searcher = new DirectorySearcher(ouEntry, ...); searcher.PropertiesToLoad.Add("displayName");
盡管您說它適用於“ givenName”,但是您可以嘗試測試第三方工具以檢查連接是否沒有問題。 例如,您可以嘗試使用LDAP Browser ,嘗試提供相同的連接數據並搜索您的過濾器字符串,然后查看它是否返回所有必需的數據。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.