Kag*_*age 4 c# active-directory
我试图让下面的代码工作,问题是,有时它确实,有时它没有.当它失败时,它会给出错误0x800704F1"系统无法联系域控制器来为身份验证请求提供服务"我说它有90%的时间失败.我已经尝试通过在上下文类型后面添加它来给它一个静态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;
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
两个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和-3167679?论坛= netfxbcl
看来,您现在必须在创建PrincipalContext时指定有效的UPN.
在创建上下文之前,您可以使用IP作为端点,现在看来它必须是正确的域名.
此外,您现在总是在发生错误时收到相同的异常 - 我们曾经为选择密码不足的用户收到密码策略例外,现在我们得到:
System.DirectoryServices.AccountManagement.PrincipalOperationException:系统无法联系域控制器来为身份验证请求提供服务.请稍后再试.(HRESULT异常:0x800704F1)
更新04-10-2016:上面显示的异常实际上是在更新后调用ChangePassword时收到的一般/一般错误.例如,如果协议中涉及的某些端口被防火墙阻止,您也可以获得此端口(如果您从未加入域的服务器/计算机上调用,则适用).
所需端口的良好资源:https://technet.microsoft.com/en-us/library/dd772723(v = ws.10).aspx 请注意,动态范围也是必需的.
如果不允许用户更改密码(域策略,通过设置下一次登录标记必须更改),您也会收到此异常.
| 归档时间: |
|
| 查看次数: |
6221 次 |
| 最近记录: |