10的Windows更新后System.DirectoryServices.AccountManagement.PrincipalContext破 [英] System.DirectoryServices.AccountManagement.PrincipalContext broken after Windows 10 update

查看:663
本文介绍了10的Windows更新后System.DirectoryServices.AccountManagement.PrincipalContext破的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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



<预类=郎-CS prettyprint-覆盖> 公共静态布尔ValidateCredentials(用户名字符串,字符串密码字符串域= NULL){
尝试{
使用(VAR principalContext = createPrincipalContext(用户名,域)){
的用户名= GetLoginInfo (用户名).Username;
//验证凭据
如果(principalContext.ValidateCredentials(用户名,密码)){
//如果帐户使用(UserPrincipal用户启用
一旦有效入住= UserPrincipal.FindByIdentity (principalContext,用户名)){
返回user.Enabled.GetValueOrDefault(假);
}
}
}
}赶上(PrincipalOperationException五){
traceError(E);
}赶上(例外五){
traceError(E);
}
返回FALSE;
}



我的开发机器自动更新到Windows 10,本周的最新版本,此后,principalContext.ValidateCredentials已经抛出以下异常



System.IO.FileNotFoundException:找不到,系统找不到指定文件



比机器更新没有别的其他的改变。我已经度过最后几天搜索网什么可能造成的问题。



任何人都可以点我在事业的方向,如果可能的话,解决方案?


解决方案

最后一个谷歌之前,我开始我的机器回滚到以前的版本,我发现这个
https://connect.microsoft.com/IE/feedback/details/ 1904887 / Windows的10内幕预览 - 构建 - 10565



该问题是由HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\丢失的注册表项引起的Microsoft\Windows NT\CurrentVersion,具体为:RegisteredOwner和RegisteredOrganization



修改
运行注册表编辑器,按视窗ř并键入REGEDIT.EXE。浏览到在注册表编辑器上面



在CURRENTVERSION只需右击位置并选择New>字符串值。在您添加的每个条目(RegisteredOwner和RegisteredOrganization)编辑值。您可以使用您的用户名和分别的公司名称。


I've been using this little function without any issue for the past few years to validate user credentials. The createPrincipalContext method returns a PrincipalContext with ContextType.Machine and the machine name.

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

My development machine automatically updated to the latest version of Windows 10 this week, and since then, principalContext.ValidateCredentials has been throwing the following exception.

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

Other than the machine update nothing else was changed. I've spend the last few days searching the net for what may have caused the issue.

Can anyone point me in the direction of a cause and if possible, a solution?

解决方案

One final Google before I started rolling back my machine to the previous build and I found this https://connect.microsoft.com/IE/feedback/details/1904887/windows-10-insider-preview-build-10565

the problem is caused by missing registry entries in HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\Windows NT\CurrentVersion, specifically: RegisteredOwner and RegisteredOrganization

EDIT: Run the Registry Editor by pressing Windows R and typing regedit.exe. Browse to the location above

Just right click on the CurrentVersion in the Registry Editor and select New > String Value. After you add each entry ( RegisteredOwner and RegisteredOrganization ) edit their values. You can use your username and company name respectively.

这篇关于10的Windows更新后System.DirectoryServices.AccountManagement.PrincipalContext破的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆