Search code examples
c#authenticationactive-directorydirectoryentry

How to use secure flag when AuthenticationTypes.Sealing is used


I am creating a Directory Entry object using

System.DirectoryServices.DirectoryEntry dirEntry = new System.DirectoryServices.DirectoryEntry(path,
                    null, null, System.DirectoryServices.AuthenticationTypes.Sealing))

It gives me warning: The Secure flag must also be set to use sealing. What do I need to do ? I can suppress the above warning by using

#pragma warning disable S4433 // LDAP connections should be authenticated

Can you please explain me what am i missing? Please note, I am using AuthenticationTypes.Sealing because I want to create and set the user password in AD in a single commit from performance perspective.

Kindly explain.


Solution

  • The AuthenticationTypes enum is bit flag, meaning that multiple values can be combined. The error is saying that you cannot use Sealing without Secure. So you must include both, which you can do with |, like this:

    DirectoryEntry dirEntry = new DirectoryEntry(path,
        null, null, AuthenticationTypes.Sealing | AuthenticationTypes.Secure);