具有使用 SSL 的上下文的 UserPrincipal

MrP*_*ram 3 c# ssl active-directory principalcontext

我有一个使用 SSL 的 PrincipalContext。这在使用 Context.ValidateCredentials() 之类的方法时效果很好。但是当我需要使用 UserPrincipal.FindByIdentity() 查找用户时,我收到以下错误:

System.Runtime.InteropServices.COMException:服务器不愿意处理请求。在 System.DirectoryServices.DirectoryEntry.Bind(Boolean throwIfFail) 在 System.DirectoryServices.DirectoryEntry.Bind() 在 System.DirectoryServices.DirectoryEntry.get_SchemaEntry() 在 System.DirectoryServices.AccountManagement.ADStoreCtx.IsContainer(DirectoryEntry de) 在 System.DirectoryServices .AccountManagement.ADStoreCtx..ctor(DirectoryEntry ctxBase, Boolean ownCtxBase, String username, String password, ContextOptions options) at System.DirectoryServices.AccountManagement.PrincipalContext.CreateContextFromDirectoryEntry(DirectoryEntry entry) at System.DirectoryServices.AccountManagement.PrincipalContext()-DoLDAPDirectory -- 内部异常堆栈跟踪结束 --- 在 System.DirectoryServices。

我的方法:

public List<string> GetUserInfo(string user) {
        var list = new List<string>();

        using (var context = new PrincipalContext(ContextType.Domain, "xxxx.xxxx.xxxx:636", "DC=xxxx,DC=xxxx,DC=xxxx", ContextOptions.SimpleBind | ContextOptions.Sealing | ContextOptions.SecureSocketLayer)) {
            var uP = UserPrincipal.FindByIdentity(context, IdentityType.SamAccountName, user);

            //Do stuff with uP
        return list;
    }
Run Code Online (Sandbox Code Playgroud)

但这工作正常:

public bool ValidateCredentials(string username, string password) {
        using (var context = new PrincipalContext(ContextType.Domain, "xxxx.xxxx.xxxx:636", "DC=xxxx,DC=xxxx,DC=xxxx", ContextOptions.SimpleBind | ContextOptions.Sealing | ContextOptions.SecureSocketLayer)) {
            return context.ValidateCredentials(username, password);
        }
    }
Run Code Online (Sandbox Code Playgroud)

为什么我不能使用带有 SSL 的上下文与 UserPrincipal 一起工作?如果我删除 SSL 它工作正常..

MrP*_*ram 5

我将 ContextOptions 更改为 Negotiate 和 SSL。然后它起作用了