2013-04-08 128 views
0

我想在我的应用程序仪表板上显示活动用户列表。Active Directory中的活动用户

我所有的用户都是员工,并通过其Active Directory凭据访问应用程序。

我已经使用UserPrincipal获取当前用户的详细信息,但是这可以为所有当前用户完成吗?

回答

2

您可以使用PrincipalSearcher和“查询通过例如”主要做你的搜索:

// create your domain context 
using (PrincipalContext ctx = new PrincipalContext(ContextType.Domain)) 
{ 
    // define a "query-by-example" principal - here, we search for all "enabled" UserPrincipal 
    UserPrincipal qbeUser = new UserPrincipal(ctx); 
    qbeUser.IsEnabled = true; 

    // create your principal searcher passing in the QBE principal  
    PrincipalSearcher srch = new PrincipalSearcher(qbeUser); 

    // find all matches 
    foreach(var found in srch.FindAll()) 
    { 
     // do whatever here - "found" is of type "Principal" - it could be user, group, computer.....   
    } 
} 

如果您尚未 - 绝对看MSDN文章Managing Directory Security Principals in the .NET Framework 3.5这很好地说明如何使System.DirectoryServices.AccountManagement中的新功能的最佳使用。或者查看MSDN documentation on the System.DirectoryServices.AccountManagement命名空间。