Skip to main content
 首页 » 编程设计

c#之DirectoryEntry.Invoke ChangePassword 上的 Active Directory 访问被拒绝异常

2024年02月06日16lori

下面的 MVC web api 代码可以正常工作

directoryEntry.Invoke("SetPassword", "desired password"); 
directoryEntry.CommitChanges(); 

但是相同的应用程序/服务帐户在尝试时出现错误

directoryEntry.Invoke("ChangePassword", "old password", "new password"); 
directoryEntry.CommitChanges(); 

错误详情: System.UnauthorizedAccessException:访问被拒绝。 (HRESULT 异常:0x80070005 (E_ACCESSDENIED))

调用 ChangePassword 需要与 SetPassword 不同的权限吗?

请您参考如下方法:

由于选中了“用户无法更改密码”设置标志,您可能会遇到访问被拒绝的错误。您希望允许更改其密码的任何用户都需要取消选中该设置。