我正在使用 DirectorySearcher.FindOne()
方法。
我已在 Active Directory 用户属性中指定了移动
号码。我的搜索过滤器看起来像这样
(&(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();
}
}
关于c# - LDAP SearchResult 不包含用户属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18130414/