gpt4 book ai didi

c# - Windows 10 更新后 System.DirectoryServices.AccountManagement.PrincipalContext 损坏

转载 作者:IT王子 更新时间:2023-10-29 04:05:59 26 4
gpt4 key购买 nike

在过去的几年里,我一直在使用这个小功能来验证用户凭据,没有任何问题。 createPrincipalContext 方法返回一个带有 ContextType.Machine 和机器名称的 PrincipalContext

public static bool ValidateCredentials(string username, string password, string domain = null) {
try {
using (var principalContext = createPrincipalContext(username, domain)) {
username = GetLoginInfo(username).Username;
// validate the credentials
if (principalContext.ValidateCredentials(username, password)) {
//once valid check if account is enabled
using (UserPrincipal user = UserPrincipal.FindByIdentity(principalContext, username)) {
return user.Enabled.GetValueOrDefault(false);
}
}
}
} catch (PrincipalOperationException e) {
traceError(e);
} catch (Exception e) {
traceError(e);
}
return false;
}

我的开发机器最近自动更新到最新版本的 Windows 10,从那时起,principalContext.ValidateCredentials 一直抛出以下异常。

System.IO.FileNotFoundException: The system cannot find the file specified.

除了机器更新之外,没有其他任何改变。在过去的几天里,我一直在网上搜索可能导致该问题的原因。

有没有人有确定可能的原因以及可能的解决方案的经验?

最佳答案

在我开始将我的机器回滚到以前的版本之前最后一次谷歌,我发现了这个 https://connect.microsoft.com/IE/feedback/details/1904887/windows-10-insider-preview-build-10565

问题是由于缺少 HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\Windows NT\CurrentVersion 中的注册表条目引起的,特别是:RegisteredOwner 和 RegisteredOrganization

编辑:通过按 Windows R 并键入 regedit.exe 运行注册表编辑器。浏览到上面的位置

只需在注册表编辑器中右键单击 CurrentVersion,然后选择新建 > 字符串值。添加每个条目(RegisteredOwner 和 RegisteredOrganization)后编辑它们的值。您可以分别使用您的用户名和公司名称。

关于c# - Windows 10 更新后 System.DirectoryServices.AccountManagement.PrincipalContext 损坏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33717673/

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