Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-core/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net core 从NetCore 2.0中的active directory获取所有用户_Asp.net Core_Active Directory_Ldap_Novell - Fatal编程技术网

Asp.net core 从NetCore 2.0中的active directory获取所有用户

Asp.net core 从NetCore 2.0中的active directory获取所有用户,asp.net-core,active-directory,ldap,novell,Asp.net Core,Active Directory,Ldap,Novell,所有问题都与.NET框架有关,但与.NET核心无关。我正在寻找如何从NETCORE的广告组获得所有用户的信息 我正在使用Novell.Directory.Ldap包连接到Ldap以验证我的用户 Project.csproj <PackageReference Include="Novell.Directory.Ldap.NETStandard" Version="2.3.8" /> Config.json "Ldap": { "url": "[Ldap URL]", "domain

所有问题都与.NET框架有关,但与.NET核心无关。我正在寻找如何从NETCORE的广告组获得所有用户的信息

我正在使用Novell.Directory.Ldap包连接到Ldap以验证我的用户

Project.csproj

<PackageReference Include="Novell.Directory.Ldap.NETStandard" Version="2.3.8" />
Config.json

"Ldap": {
"url": "[Ldap URL]",
"domain": "[Domain Name]"
 }

我正在使用Novell.Directory.Ldap包连接到Ldap以验证我的用户

Project.csproj

<PackageReference Include="Novell.Directory.Ldap.NETStandard" Version="2.3.8" />
Config.json

"Ldap": {
"url": "[Ldap URL]",
"domain": "[Domain Name]"
 }

如果只计划在Windows中运行应用程序,则可以从NuGet添加到项目中,其中包括名称空间,以便可以像在完整的.NET Framework中一样使用/或名称空间


但是如果你计划在其他操作系统上运行这个,那么我认为唯一的选择是Novell的库,正如Steve在他的回答中提到的。

如果你只计划在Windows上运行你的应用程序,你可以从NuGet添加到你的项目中,其中包括名称空间,这样你就可以像在完整的.NET框架中一样使用/或名称空间


但是如果你打算在其他操作系统上运行这个,那么我认为唯一的选择就是Novell的库,正如Steve在回答中提到的。

我使用的是.Net Core 3.1,但你也可以使用.Net Core 2

首先安装NuGet包“System.DirectoryServices.AccountManagement”

然后,您可以使用以下代码获取所有广告用户:

using System.DirectoryServices.AccountManagement; 


public static List<ADUser> GetADUsers() {

    var myDomainUsers = new List<ADUser>();

    using (var ctx = new PrincipalContext(ContextType.Domain, "yourdomain"))
    {

        var userPrinciple = new UserPrincipal(ctx);

        using (var search = new PrincipalSearcher(userPrinciple))
        {
            foreach (UserPrincipal domainUser in search.FindAll().OrderBy(u => u.DisplayName))
            {
                var adUser = new ADUser() {
                    Description = domainUser.Description,
                    DisplayName = domainUser.DisplayName,
                    DistinguishedName = domainUser.DistinguishedName,
                    EmailAddress = domainUser.EmailAddress,
                    Name = domainUser.Name,
                    EmployeeId = domainUser.EmployeeId,
                    GivenName = domainUser.GivenName,
                    MiddleName = domainUser.MiddleName,
                    Surname = domainUser.Surname,
                    SamAccountName  = domainUser.SamAccountName
                }; 
                myDomainUsers.Add(adUser);
            } //foreach
        } //using
    } //using

    return myDomainUsers;

} //GetADGroups

您可以从AD中提取更多属性。请查看

我使用的是.Net Core 3.1,但您也可以使用.Net Core 2

首先安装NuGet包“System.DirectoryServices.AccountManagement”

然后,您可以使用以下代码获取所有广告用户:

using System.DirectoryServices.AccountManagement; 


public static List<ADUser> GetADUsers() {

    var myDomainUsers = new List<ADUser>();

    using (var ctx = new PrincipalContext(ContextType.Domain, "yourdomain"))
    {

        var userPrinciple = new UserPrincipal(ctx);

        using (var search = new PrincipalSearcher(userPrinciple))
        {
            foreach (UserPrincipal domainUser in search.FindAll().OrderBy(u => u.DisplayName))
            {
                var adUser = new ADUser() {
                    Description = domainUser.Description,
                    DisplayName = domainUser.DisplayName,
                    DistinguishedName = domainUser.DistinguishedName,
                    EmailAddress = domainUser.EmailAddress,
                    Name = domainUser.Name,
                    EmployeeId = domainUser.EmployeeId,
                    GivenName = domainUser.GivenName,
                    MiddleName = domainUser.MiddleName,
                    Surname = domainUser.Surname,
                    SamAccountName  = domainUser.SamAccountName
                }; 
                myDomainUsers.Add(adUser);
            } //foreach
        } //using
    } //using

    return myDomainUsers;

} //GetADGroups
您可以从广告中提取更多属性。请查看