Keep getting exceptions using PrincipalContext from the System.DirectoryServices.AccountManagement assembly

3

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.

c#
exception
active-directory
asked on Stack Overflow Apr 27, 2009 by user96021 • edited Sep 13, 2010 by Johnno Nolan

3 Answers

7

Remove LDAP:// from the container string you're passing along.

It should work fine after that.

answered on Stack Overflow Oct 24, 2012 by Marco • edited Oct 24, 2012 by j0k
0

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.

Marc

answered on Stack Overflow May 31, 2009 by marc_s
0

User contributions licensed under CC BY-SA 3.0