【问题标题】:Linux Hosting & .NET Core Docker : PlatformNotSupportedException: System.DirectoryServices.AccountManagement is not supported on this platformLinux 托管和 .NET Core Docker:PlatformNotSupportedException:此平台不支持 System.DirectoryServices.AccountManagement
【发布时间】:2018-08-03 05:09:00
【问题描述】:

我在 .NET Core 2.0 中实现了 Web api,并实现了基本身份验证和 Active Directory。我们正在使用 docker 进行部署。以下是我为 Active Directory 身份验证编写的代码:

 using (PrincipalContext pContext = new PrincipalContext(ContextType.Domain, "xyz"))
            {
                try
                {
                    // validate the credentials
                    bool isValid = pContext.ValidateCredentials(userName, password, ContextOptions.Negotiate | ContextOptions.Signing | ContextOptions.Sealing);

                    if (!isValid)
                    {
                        return false;
                    }
                }
                catch(Exception)
                {
                    return false;
                }
                return true;
            }

为了使用 PrincipalContext,我添加了

的参考

System.DirectoryServices.AccountManagement;

这完全可以在 Windows 机器上运行。使用 Docker 容器也可以在 Windows 环境中正常工作。但是我们的生产服务器是基于 Linux 的,它不能在 Linux 托管系统上运行。它显示类似的错误

PlatformNotSupportedException:此平台不支持 System.DirectoryServices.AccountManagement。

可以做些什么来让它发挥作用?

谢谢!

【问题讨论】:

    标签: docker active-directory dockerfile asp.net-core-2.0 basic-authentication


    【解决方案1】:

    当我们使用 docker 容器来托管我们的应用程序时,不支持命名空间 (System.DirectoryServices.AccountManagement)。但是我们可以使用这个 nuget 包https://github.com/dsbenghe/Novell.Directory.Ldap.NETStandard 及其与 docker 容器托管一起使用来进行类似的设置来验证 Active Directory 上的用户凭据。

    // using Novell.Directory.Ldap;
    
    try
    {
        using (var connection = new LdapConnection())
        {
            connection.Connect("DomainUrl", 389);
            connection.Bind("username@domain", "password");
            if (connection.Bound)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
    }
    catch (LdapException ex)
    {
        return false;
    }
    

    【讨论】:

      【解决方案2】:

      自动我认为你不能这样做,因为异常说活动目录 API 在 Linux 中不可用。一种解决方法是构建一个 windows Docker 容器或 windows 服务

      【讨论】:

      • 我们可以在 Linux 服务器上托管 Windows 容器吗?我是 Docker 的新手。所以没有详细的知识
      • 我认为你不能在 Linux 服务器上运行 windows 容器。你需要一个虚拟机。
      猜你喜欢
      • 2020-10-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-08-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-12-29
      相关资源
      最近更新 更多