I am having some problems accessing Active Directory from my WinForm application. I want to create a user and request a user from Active Directory.
Here is a snippet of code to search for a user:
public bool FindUser(string username) { using (PrincipalContext context = new PrincipalContext( ContextType.Domain, this.domainName, this.DomainUserName, this.DomainPassword)) { UserPrincipal user = UserPrincipal.FindByIdentity(context, username); return (user != null) ? true : false; } }
I cannot create a PrincipalContext object based on the given arguments. I get this exception:
Exception: The server could not be contacted.
and internal exception indicates that
Inner Exception: The LDAP server is unavailable.
when the domain is working. I can ping and connect to this domain.
c # active-directory
Mohsan
source share