[英]LDAP SearchResult does not contain user properties
我正在使用DirectorySearcher.FindOne()
方法。
我在Active Directory用戶屬性中指定了Mobile
號碼。 我的搜索過濾器看起來像這樣
(&(ObjectClass=User)(mobile=+11111111111))
有了這個過濾器,我就能找到合適的用戶。
我還在AD用戶屬性中指定了傳真號碼,但是SearchResult
不包含傳真屬性。 實際上SearchResult
僅包含一個屬性,但是我希望返回所有用戶屬性,包括傳真號碼。
我應該修改查詢以獲取傳真號碼嗎? 也許需要更改我的AD用戶或LDAP服務器?
使用DirectorySearcher
,可以使用PropertiesToLoad
集合定義將哪些屬性包括在SearchResult
。 如果您未指定任何內容,則只會獲得專有的LDAP名稱
所以嘗試這樣的事情:
DirectoryEntry root = new DirectoryEntry("LDAP://-your-base-LDAP-path-here-");
DirectorySearcher searcher = new DirectorySearcher(root);
searcher.Filter = "(&(ObjectClass=User)(mobile=+11111111111))";
// DEFINE what properties you need !
searcher.PropertiesToLoad.Add("Mobile");
searcher.PropertiesToLoad.Add("Fax");
SearchResult result = searcher.FindOne();
if (result != null)
{
if (result.Properties["Fax"] != null)
{
string fax = result.Properties["Fax"][0].ToString();
}
if (result.Properties["Mobile"] != null)
{
string mobile = result.Properties["Mobile"][0].ToString();
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.