发布网友 发布时间:2024-10-05 10:06
共3个回答
热心网友 时间:2024-10-05 10:01
如果你是找用户应该是 :
searcher.Filter ="(objectClass=user)";
然后遍历 searcher.FindAll()
foreach (SearchResult result in searcher.FindAll())
{
///
}
热心网友 时间:2024-10-05 10:06
/// <summary>
/// 根据公共名称获取用户对象
/// </summary>
/// <param name="commonName">用户名称</param>
/// <returns>DirectoryEntry</returns>
public static DirectoryEntry GetDirectoryEntry(string commonName)
{
DirectoryEntry de = GetObjectByAdmin();
DirectorySearcher deSearch = new DirectorySearcher(de);
deSearch.Filter = "(&(&(objectCategory=person)(objectClass=user))(cn=" + commonName + "))";
deSearch.SearchScope = SearchScope.Subtree;
try
{
SearchResult result = deSearch.FindOne();
de = new DirectoryEntry(result.Path);
return de;
}
catch
{
return null;
}
热心网友 时间:2024-10-05 10:08
风光好