使用System.DirectoryServices.AccountManagement程序集中的PrincipalContext继续获取异常

use*_*021 3 c# exception active-directory

使用System.DirectoryServices.AccountManagement程序集.

我正在使用构造函数

 PrincipalContext context = new PrincipalContext(
                ContextType.Domain,
                "myserver.ds.com", 
                "LDAP://OU=the-users,DC=myserver,DC=ds,DC=com", 
                adusername, 
                password);
Run Code Online (Sandbox Code Playgroud)

我可以打电话context.ValidateCredentials(adusername, password, ContextOptions.ServerBinding),它返回true.

只要我调用UserPrincipal.FindByIdentity(context,IdentityType.SamAccountName,username);

我得到了各种PrincipalOperationException.有时是"服务器发送推荐人".其他时候是未知错误(0x80005000)

我正在使用这些重载,因为有问题的服务器不在运行程序的用户所在的域中.

无论如何,如何解决这个问题以及对程序论证的一些启示将是最受欢迎的.

提前致谢.

小智 7

LDAP://从您传递的容器字符串中删除.

之后应该可以正常工作.