0
我想從活動目錄中獲取用戶名。我使用下面的代碼,它給了我一些人的用戶名,但它不是全部。有缺少的名字。我錯了什麼?我是Mvc和ldap的新手。任何人都可以幫助我?如何從MVC中的活動目錄獲取用戶列表?
public ActionResult GetUserList()
{
DirectoryEntry entry = new DirectoryEntry("LDAP://domain.com", "username", "password");
DirectorySearcher searcher;
SearchResultCollection results;
searcher = new DirectorySearcher(entry);
searcher.Filter = "(&(objectClass=user)(displayname=*))";
searcher.SearchScope = SearchScope.Subtree;
List<string> list= new List<string>();
using (searcher)
{
results = searcher.FindAll();
foreach (SearchResult result in results)
{
string searchOK = result.Properties["displayname"][0].ToString();
list.Add(searchOK);
}
}
return View(list);
}