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

查看:18
本文介绍了如何在 .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?

我是 Active Directory 的新手,使用 .net core2.0.

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

感谢任何建议和指导.

推荐答案

有一个用于 .NET Core 2 的 System.DirectoryServices.AccountManagement 实现,由 .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天全站免登陆