gpt4 book ai didi

c# - 具有使用 SSL 的上下文的 UserPrincipal

转载 作者:太空宇宙 更新时间:2023-11-03 14:08:38 24 4
gpt4 key购买 nike

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

System.Runtime.InteropServices.COMException: The server is unwilling to process the request. at System.DirectoryServices.DirectoryEntry.Bind(Boolean throwIfFail) at System.DirectoryServices.DirectoryEntry.Bind() at System.DirectoryServices.DirectoryEntry.get_SchemaEntry() at System.DirectoryServices.AccountManagement.ADStoreCtx.IsContainer(DirectoryEntry de) at 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.DoLDAPDirectoryInit() --- End of inner exception stack trace --- at System.DirectoryServices.AccountManagement.PrincipalContext.DoLDAPDirectoryInit() at System.DirectoryServices.AccountManagement.PrincipalContext.DoDomainInit() at System.DirectoryServices.AccountManagement.PrincipalContext.Initialize() at System.DirectoryServices.AccountManagement.PrincipalContext.get_QueryCtx() at System.DirectoryServices.AccountManagement.Principal.FindByIdentityWithTypeHelper(PrincipalContext context, Type principalType, Nullable`1 identityType, String identityValue, DateTime refDate) at System.DirectoryServices.AccountManagement.Principal.FindByIdentityWithType(PrincipalContext context, Type principalType, String identityValue) at System.DirectoryServices.AccountManagement.UserPrincipal.FindByIdentity(PrincipalContext context, String identityValue)

我的方法:

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;
}

但这工作正常:

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);
}
}

为什么我不能使用带 SSL 的上下文来处理 UserPrincipal?如果我删除 SSL 它工作正常..

最佳答案

我将 ContextOptions 更改为协商和 SSL。然后就成功了

关于c# - 具有使用 SSL 的上下文的 UserPrincipal,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35840067/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com