我试图让下面的代码工作,问题是,有时可以,有时不可以。
当失败时,会出现错误 0x800704F1“系统无法联系域控制器来服务身份验证请求”
我想说大约 90% 的情况都会失败。
我尝试通过将其添加到 contexttype 后面来给它一个静态 DC,遗憾的是这没有帮助。
在管理员用户上它始终有效..但是我确实相信用户应该能够更改自己的密码。
该错误是在 user.changepassword 行上触发的
我希望其他人有一个好主意。
using (var context = new PrincipalContext(ContextType.Domain))
{
using (var user = UserPrincipal.Current)
{
try
{
user.ChangePassword(txt_old.Text, txt_new.Text);
user.Save();
}
catch(Exception p)
{
if (p.HResult.Equals("0x800708C5"))//Not secure enough according to password policy
{
MessageBox.Show("Volgens het systeem is uw nieuwe wachtwoord niet veilig genoeg, voldoet het aan alle eisen?", "Niet gelukt", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return;
}
else if (p.HResult.Equals("0x80070056")) //Wrong current password
{
MessageBox.Show("U heeft een verkeerd huidig wachtwoord ingevult, probeer het nogmaals", "Verkeerd wachtwoord", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return;
}
else if (p.InnerException.ToString().Contains("0x80070775")) //Temporarly locked out.
{
MessageBox.Show("Uw account is tijdelijk vergrendeld door te veel pogingen tot in te loggen met een foutief wachtwoord. Probeer het over 15minuten nogmaals of neem contact op met de helpdesk.", "vergrendeld.", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return;
}
else
{
MessageBox.Show(System.Security.Principal.WindowsIdentity.GetCurrent().Name + Environment.NewLine + p.HResult + Environment.NewLine + p.Message);
return;
}
}
}
}
两个 Windows 更新 3177108 和 3167679 更改了 ChangePassword 的行为。
这里有一个关于这个问题的线程:https://social.msdn.microsoft.com/Forums/vstudio/en-US/77dc733e-a13d-4349-9088-8065b85d5c3f/userprincipalchangepassword-stops-working-after-windows-updates-3177108-and-3167679?forum= NETFXBCL https://social.msdn.microsoft.com/Forums/vstudio/en-US/77dc733e-a13d-4349-9088-8065b85d5c3f/userprincipalchangepassword-stops-working-after-windows-updates-3177108-and-3167679?forum=netfxbcl
看来,您现在必须在创建 PrimaryContext 时指定有效的 UPN。
在创建上下文时可以使用 IP 作为端点之前,现在看来它也必须是正确的域名。
此外,现在,当发生错误时,您总是会收到相同的异常 - 我们过去会因用户选择的密码不足而收到密码策略异常,现在我们得到:
System.DirectoryServices.AccountManagement.PrincipalOperationException:
系统无法联系域控制器来提供服务
身份验证请求。请稍后再试。 (例外情况来自
H结果:0x800704F1)
2016 年 10 月 4 日更新:
上面显示的异常实际上是更新后调用 ChangePassword 时收到的几乎所有错误。
例如,如果协议中涉及的某些端口被防火墙阻止,您也会得到这个端口(如果您从未加入域的服务器/计算机进行调用,则适用)。
所需端口的良好资源:https://technet.microsoft.com/en-us/library/dd772723(v=ws.10).aspx https://technet.microsoft.com/en-us/library/dd772723(v=ws.10).aspx请注意,动态范围也是必需的。
如果不允许用户更改密码(域策略,通过设置“下次登录标志时必须更改”来规避),您也会收到此异常。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)