如何在.net Core 2中的活动目录上获取用户/组列表

0 active-directory .net-core asp.net-core

正在处理一个项目,其中所有用户都在域下的活动目录中创建。

我想要的是获取域中的所有用户,这可能吗?

我对使用.net core2.0的活动目录是陌生的。

任何建议和指导表示赞赏。

hil*_*tuk 8

System.DirectoryServices.AccountManagement.NET Foundation发布了.NET Core 2 的实现。在这里查看nuget参考

这样您就可以拨打这样的电话:

    using (var ctx = new PrincipalContext(ContextType.Domain, "MyDomain")){
        var myDomainUsers = new List<string>();
        var userPrinciple = new UserPrincipal(ctx);
        using (var search = new PrincipalSearcher(userPrinciple)){
            foreach (var domainUser in search.FindAll()){
                if (domainUser.DisplayName != null){
                    myDomainUsers.Add(domainUser.DisplayName);
                }
            }
        }
     }
Run Code Online (Sandbox Code Playgroud)