C# : Error while accessing Active Directory
- by Mohsan
hi. i am facing some problems in accessing Active Directory from my winform app. what I want is to create a user and query user from Active Directory.
here is code snippet for find 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 am unable to create object of PrincipalContext based on given arguments. i am getting this exception "{"The server could not be contacted."}"
and inner exception states that "{"The LDAP server is unavailable."}"
where as domain is running. i can ping to it and can also connect to this domain.
any suggestion about these exceptions?