我们正在编写一个系统,允许用户通过我们内部网上的 Web 应用程序更改他们的帐户密码。
起初,一切似乎都很顺利。在开发过程中,我们的测试帐户的密码可以毫无问题地更改。
然而,当我们使系统上线时,我们开始遇到问题。以下是症状:
- 起初,一切都很好。用户可以更改他们的密码。
- 在某些时候,UserPrincipal.FindByIdentity 中出现以下错误:“System.Runtime.InteropServices.COMException:身份验证机制未知。”
- 从那时起,尝试通过 Web 应用程序更改密码会导致错误:“System.Runtime.InteropServices.COMException:服务器无法运行。”
- 如果我手动回收应用程序池,一切似乎都会自行修复,直到开始发生更多错误......即,该过程在阶段 1 重新开始。
这是相关的代码片段:
private static PrincipalContext CreateManagementContext() {
return new PrincipalContext(
ContextType.Domain,
ActiveDirectoryDomain,
ActiveDirectoryManagementAccountName,
ActiveDirectoryManagementAccountPassword);
}
private static void ChangeActiveDirectoryPasword(string username, string password) {
if (username == null) throw new ArgumentNullException("username");
if (password == null) throw new ArgumentNullException("password");
using (var context = CreateManagementContext())
using (var user = UserPrincipal.FindByIdentity(context, IdentityType.SamAccountName, username)) {
user.SetPassword(password);
}
}
关于为什么会发生这种情况的任何线索?谷歌搜索并没有发现任何真正有用的东西,MSDN 上的文档也没有。