Using System.DirectoryServices.AccountManagement assembly.
I am using the constructor
PrincipalContext context = new PrincipalContext( ContextType.Domain, "myserver.ds.com", "LDAP://OU=the-users,DC=myserver,DC=ds,DC=com", adusername, password);
I can call
context.ValidateCredentials(adusername, password, ContextOptions.ServerBinding) and it returns true.
As soon as I call UserPrincipal.FindByIdentity(context, IdentityType.SamAccountName, username);
I get various PrincipalOperationException. Sometimes is a "server sent a referrer". Other times it is Unknown error (0x80005000)
I'm using these overloads because the server in question in not in the same domain that the user running the program is in.
Anyhow, how to fix this and possibly some enlightenment to the procedure arguments would be most appreciated.
Thanks in Advance.
LDAP:// from the container string you're passing along.
It should work fine after that.
Can you tell us what values exactly you're sending into the
FindByIdentity ? The creation of the PrincipalContext seems to be just fine, and if it can validate the user credentials, your connection should be fine, too. Quite possibly there's something wrong with the parameters being passed into FindByIdentity.
Note that there's a bug in .NET 4.0 with FindByIdentity().
User contributions licensed under CC BY-SA 3.0