我在使用WinForm应用程序访问Active Directory时遇到了一些问题。我的目标是在Active Directory中创建用户并查询用户。
以下是查找用户的代码片段:
以下是查找用户的代码片段:
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;
}
}
我无法基于给定的参数创建PrincipalContext
对象。我遇到了以下异常:
Exception: The server could not be contacted.
内部异常说明:
Inner Exception: The LDAP server is unavailable.
在域名运行时,我可以对其进行ping测试并连接到该域名。