Working with DirectoryServices in ASP.NET Core

前端 未结 5 1747
说谎
说谎 2021-02-02 14:22

I am upgrading my ASP.NET Core RC1 application to RC2. I have some references to System.DirectoryServices and System.DirectoryServices.AccountManagement

5条回答
  •  独厮守ぢ
    2021-02-02 14:39

    You can use LDAP client library for .NET Standard 1.3
    Compatible .NET runtimes: .NET Core, .NET Framework 4.6, ...
    It works against any LDAP protocol compatible directory server (including Microsoft Active Directory).

    private static bool LoginLdap(string username, string password)
    {
        try
        {
            using (var conn = new LdapConnection())
            {
                conn.Connect("", 389);
                conn.Bind(LdapConnection.Ldap_V3, $"\\{username}", password);
            }
            return true;
        }
        catch (LdapException)
        {
            return false;
        }            
    }
    

    For more info read this issue : Support for System.DirectoryServices
    It works well for me. (in .NET Core 1.1.1)

提交回复
热议问题