In a recent project I had to validate that a user was valid against Active Directory. I'm not that good at LDAP queries so I thought I'd document this code in case it came up again.
The code shows a successful and failed lookup against a domain. Note that there is no password, we're only validating that the user exists.
I'm showing two different approacher, one uses the DirectoryServices namespace and the other uses DirectoryServices.AccountManagement. I'm not expert enough to know which is better... I just need the end result.