如何在.net Core 2中的活动目录上获取用户/组列表 [英] How to get users/group list on active directory in .net core 2

查看:140
本文介绍了如何在.net Core 2中的活动目录上获取用户/组列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Working on a project, where all users are created in active directory under a domain.

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

What I want is get all users that are in the domain, is this possible?

我是使用.net core2.0主动目录的新手。

I am new to active directory, using .net core2.0.

任何建议和指导都值得赞赏。

Any suggestions and guidance is appreciated.

推荐答案

有一个 System.DirectoryServices.AccountManagement 的实现。 .NET Core 2,由.Net Foundation发布。请参阅nuget参考这里

There is an implementation of System.DirectoryServices.AccountManagement for .NET Core 2, published by the .Net Foundation. See the nuget reference here

这将允许您拨打这样的电话:

This will allow you to make calls like this:

    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);
                }
            }
        }
     }

这篇关于如何在.net Core 2中的活动目录上获取用户/组列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆