【问题标题】:Active Users in application from Active Directory来自 Active Directory 的应用程序中的活动用户
【发布时间】:2013-04-08 14:29:23
【问题描述】:

我想在我的应用程序的仪表板上显示一个活跃用户列表。

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

我已经使用 UserPrincipal 来获取当前用户的详细信息,但是可以为所有当前用户执行此操作吗?

【问题讨论】:

    标签: asp.net-mvc active-directory


    【解决方案1】:

    您可以使用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 命名空间。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-08-12
      • 2023-03-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-12-27
      相关资源
      最近更新 更多