本文介绍了以层次结构顺序获取活动目录中的所有内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想按层次顺序获取域中的所有OU并将其绑定到MVC中的树视图。
我尝试过:
我尝试了下面的代码,但它返回空。
I would like to get all OUs in a domain in hierarchical order and bind it to tree view in MVC.
What I have tried:
I tried below code but it returns empty.
Domain domain = Domain.GetDomain(new DirectoryContext(DirectoryContextType.Domain, "domainname", "username", "password"));
Forest forest = domain.Forest;
DomainCollection domains = forest.Domains;
但是如果我使用这段代码,我会得到OU列表但不是我想要的。
But if I use this code I get list of OUs but not how I want.
List<string> lstName = new List<string>();
DirectoryEntry directoryEntry = new DirectoryEntry("LDAP://DC=domainname,DC=com", "username", "password");
DirectorySearcher oDirectorySearcher = new DirectorySearcher(directoryEntry,"(objectCategory=organizationalUnit)", null);
SearchResultCollection oSearchResultCollection = oDirectorySearcher.FindAll();
foreach (SearchResult item in oSearchResultCollection)
{
string name = item.Properties["name"][0].ToString();
lstName.Add(name);
}
有人可以帮忙吗?
谢谢
Can anyone help?
Thanks
推荐答案
这篇关于以层次结构顺序获取活动目录中的所有内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!