DirectoryEntry.Invoke(“SetPassword”,new object [] {password});在asp.net应用程序中给出访问被拒绝错误

时间:2014-08-31 05:30:41

标签: asp.net active-directory directoryservices

DirectoryEntry.Invoke("SetPassword", new object[] { password });

在ASP.NET应用程序中出错,而它在控制台应用程序中完美运行。

这是我得到的错误:

  

调用目标抛出了异常。

内部错误为Access Denied

2 个答案:

答案 0 :(得分:2)

ASP.NET运行的安全上下文与从命令行运行某些内容时的安全上下文不同。检查您的应用程序池的运行情况。它通常作为低权限用户运行。

答案 1 :(得分:-1)

以上问题已解决

using (var context = new PrincipalContext(ContextType.Domain, "DomainName", null, "UserName", "Password"))
{
    using (var user = UserPrincipal.FindByIdentity(context, IdentityType.SamAccountName, "username"))
    {
            user.SetPassword("Password");
    }
}