1

I have a project using .NET Core. I have a problem with authenticating LDAP connection. In .net framework, it's possible to authenticate LDAP connection without username and password but it's seems unable to work in .NET Core.

Now how do you authenticate a connection in LDAP using PrincipalContext without providing username and password? In .NET Core? Thanks in advance .

Below is my sample code:

using System.DirectoryServices.AccountManagement;

....
using(PrincipalContext ctx = new PrincipalContext(ContextType.Domain, "123.123.123.123"))
{
    using (UserPrincipal user = UserPrincipal.FindByIdentity(ctx, IdentityType.SamAccountName, "hreyes"))
    {
        if(user != null)
        {
            string email = user.EmailAddress;
        }
    }
}
ArunPratap
  • 4,816
  • 7
  • 25
  • 43

0 Answers0