C# AD用户ChangePassword错误0x80070056指定的网络密码不正确
我正在寻求有关更改广告用户密码的C#ASP网络程序的帮助。
大多数情况下它运行良好,但有时我有这种情况:
例外:0x80070056 指定的网络密码不正确 System.DirectoryServices.AccountManagement.Adstorectx.ChangePassword(Authenticable Principal P,String old oldpassword,string newPassword)
这是我的代码:
PrincipalContext ad = new PrincipalContext(ContextType.Domain, "adomaincontroller", "specificOU", "domainadmin", "password");
if (ad.ValidateCredentials(model.UserName, model.OldPassword))
{
ModifyPassword("adomaincontroller", model.UserName, model.OldPassword, model.Password);
return RedirectToAction("ChangePassword", "ChangePassword");
}
public void ModifyPassword(string domain, string userName, string oldPassword, string newPassword)
{
try
{
using (var context = new PrincipalContext(ContextType.Domain, domain))
using (var user = UserPrincipal.FindByIdentity(context, IdentityType.SamAccountName, userName))
{
user.ChangePassword(oldPassword, newPassword);
}
}
catch (Exception ex)
{
some stuf to log error here
}
}
我可以向您保证指定的旧密码正确。我使用valialatecredentials进行检查。
因此,在某些情况下,此错误已征得,但是...用户的密码无论如何都会更改,因此它有效,但是Apperead ...我不忘记。
我看到了有关此错误的一些线程,谈到Windows KB,但这并不是我的情况。
感谢您的帮助
I'm asking for help about a C# asp net program that change password of ad users.
It works well most of the time, but sometimes i have this case :
Exception de HRESULT : 0x80070056
The specified network password is not correct
System.DirectoryServices.AccountManagement.ADStoreCtx.ChangePassword(AuthenticablePrincipal p, String oldPassword, String newPassword)
This is my code :
PrincipalContext ad = new PrincipalContext(ContextType.Domain, "adomaincontroller", "specificOU", "domainadmin", "password");
if (ad.ValidateCredentials(model.UserName, model.OldPassword))
{
ModifyPassword("adomaincontroller", model.UserName, model.OldPassword, model.Password);
return RedirectToAction("ChangePassword", "ChangePassword");
}
public void ModifyPassword(string domain, string userName, string oldPassword, string newPassword)
{
try
{
using (var context = new PrincipalContext(ContextType.Domain, domain))
using (var user = UserPrincipal.FindByIdentity(context, IdentityType.SamAccountName, userName))
{
user.ChangePassword(oldPassword, newPassword);
}
}
catch (Exception ex)
{
some stuf to log error here
}
}
I can assure you the old password specified is correct. I check it with ValidateCredentials.
So in some case this error hapenned, but ... the user's password is changed anyway, so it works but the error apperead ... I don't undestand.
I saw some threads about this error, speaking about windows KB, but its aparently not my case.
Thanks for help
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论