In one of our applications we are connecting with LDAP through System.DirectoryServices.AccountManagement.
. This code worked fine for years until we had to make the switch from LDAP to LDAPS and incorporate SSL in our connections.
Let me start by showing you the original code (or at least a part of it):
We thought that making the switch to SSL would be easy. We therefore added the ContextOptions.SecureSocketLayer
to the ContextOptions
enum;
However after doing that, we get a SmartCard popup everytime this code is called:
I couldn’t find a good solution to fix it while keeping the PrincipalContext
class. After some help of GitHub Copilot and some research I discovered that I could get it working when I switched to the underlying LdapConnection
and explicitly setting the ClientCertificate
to null
:
More information
c# - PrincipalContext with smartcard inserted - Stack Overflow
c# - How to validate server SSL certificate for LDAP+SSL connection - Stack Overflow