繁体   English   中英

Windows 10更新后,System.DirectoryServices.AccountManagement.PrincipalContext中断

[英]System.DirectoryServices.AccountManagement.PrincipalContext broken after Windows 10 update

在过去的几年里,我一直在使用这个小功能,没有任何问题来验证用户凭据。 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:系统找不到指定的文件。

除了机器更新,没有其他更改。 我花了最近几天在网上搜索可能导致问题的原因。

有没有人有任何经验可以确定原因,如果可能的话,还有解决方案?

在我开始将我的机器回滚到之前的版本之前的最后一个Google,我发现了这个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,然后选择New> String Value。 添加每个条目(RegisteredOwner和RegisteredOrganization)后,编辑它们的值。 您可以分别使用您的用户名和公司名称。

在Build选项卡下的项目属性窗口中取消选中 Prefer 32-bit复选框,默认情况下会选中它 - 参见屏幕截图。 这为我修好了! 再次选中该复选框将导致您描述的例外重新出现。 我猜这会强制它在64位模式下运行,如果可能的话,因此使用64位注册表路径而不是WOW6432Node注册表路径,因此它将找到所需的正确密钥。

取消选中“Prefer 32-bit”屏幕截图

尝试将您的构建平台目标更改为“AnyCPU” ,我发现如果我的平台目标是x86,我有这个问题!

为什么,但不知道,似乎赢得10个bug!

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM