0
所以我一直在瘋狂地試圖找出爲什麼我無法讓我的LDAP搜索工作。ASP.NET綁定和查詢LDAP
private String getDNFromLDAP(String strUID)
{
String strDN = "";
//Create an LDAP Entry Object
DirectoryEntry entry = new DirectoryEntry("LDAP://something.blah.com/cn=people,dc=blah,dc=com");
entry.AuthenticationType = AuthenticationTypes.SecureSocketsLayer;
entry.Username = "cn=myaccount,cn=special,dc=blah,dc=com";
entry.Password = "supersecret";
DirectorySearcher mySearcher = new DirectorySearcher(entry);
mySearcher.SearchScope = SearchScope.Subtree;
mySearcher.Filter = "(uid=" + strUID + ")";
SearchResult result = mySearcher.FindOne();
int nIndex = result.Path.LastIndexOf("/");
strDN = result.Path.Substring((nIndex + 1)).ToString().TrimEnd();
//Clean up objects
entry.Close();
entry.Dispose();
mySearcher.Dispose();
//returns the DN
return strDN;
}
我知道我在尋找存在對象(ldapsearch的確認),但我的成績一直回來空。我懷疑基本dn存在問題,但我不知道如何確認DirectorySearch用作基本dn的內容。任何幫助都將不勝感激。
據我瞭解,我使用的DirectorySearcher構造函數接受我的DirectoryEntry的值並使用它來設置searchroot屬性。 http://msdn.microsoft.com/en-us/library/y49s2h23.aspx 我誤解了嗎? – DR913
你是對的。我的想法是,因爲這是搜索的根源,也許你的搜索無法找到你正在尋找的條目。您可以通過將搜索根更改爲父節點並查看如何繼續進行確認。 –
經過三天的這段代碼戰鬥,結果證明我有一個權限問題。通過修改搜索根來找出它。 – DR913