【发布时间】:2016-01-24 02:02:48
【问题描述】:
以下适用于 Windows 的多个服务器版本,以及 Windows 7 pro 和其他版本,但在 Windows 10(至少两台机器)上我收到错误:“系统找不到指定的文件。\r\n”。错误来源是“Active Directory”
System.IO.FileNotFoundException:系统找不到指定的文件。
堆栈跟踪:
at System.DirectoryServices.AccountManagement.UnsafeNativeMethods.IADs.Get(String bstrName)
at System.DirectoryServices.AccountManagement.CredentialValidator.BindSam(String target, String userName, String password)
at System.DirectoryServices.AccountManagement.CredentialValidator.Validate(String userName, String password)
at System.DirectoryServices.AccountManagement.PrincipalContext.ValidateCredentials(String userName, String password)
at IsValidWindowsUser(String userName, String password) in MembershipProvider.cs:line xxx
以下是触发错误所需的最少代码量。在这种情况下,我使用的是 ValidateCredentials() 但其他操作(例如 PrincipalSearches)也会失败并出现完全相同的错误。
我已使用 LogonUser() 验证了凭据是否有效; https://msdn.microsoft.com/en-us/library/windows/desktop/aa378184(v=vs.85).aspx
bool IsValidWindowsUser(string userName, string password)
{
using (var p = new PrincipalContext(ContextType.Machine))
return p.ValidateCredentials(userName, password);
}
重要提示:我发现这可以在两个 Windows 10 系统上运行,但从那时起,两个系统的硬盘驱动器都被固态驱动器取代。操作系统移动是使用磁盘映像软件完成的,操作系统上的所有其他内容都完好无损。我知道磁盘/分区签名已更改。这会破坏/损坏然后凭证存储吗?一台 Windows 7 pro 计算机也更换了驱动器,但仍能正常工作。
另一个可能相关的老问题是:Validate a users credentials on the local machine
这个问题似乎也谈到了 PrincipalContext(ContextType.Machine) 的 FileNotFoundException 异常,但前提是没有网络连接。就我而言,总是有网络连接。我会使用 LogonUser,但我还需要测试组成员身份。
【问题讨论】:
标签: c# windows active-directory