在Web应用程序中更改Windows密码

时间:2012-09-28 20:30:27

标签: asp.net .net c#-4.0 iis workgroup

我有一个使用https和基本身份验证的网站。用户将自动针对Windows进行身份验证。该网站托管在工作组计算机上(不是域的成员)。我正在使用.NET Framework 4和C#

我尝试从网页更改用户的密码(在用户通过身份验证后),但没有成功。我使用DirectoryService尝试了几件事:

    using (DirectoryEntry directoryEntry = new DirectoryEntry(string.Format(@"WinNT://localhost/{0}, user", userName), domainAndUser, userPassword))
    {
        directoryEntry.Invoke("ChangePassword", new object[] { oldPassword, newPassword });
        directoryEntry.CommitChanges();
    }

我收到拒绝访问错误。我想我需要做管理员才能做到这一点。

我尝试做的是什么以及如何实现这一目标?

提前感谢您的回答!

基督教

1 个答案:

答案 0 :(得分:0)

您必须在工作组计算机上以管理员身份运行该代码,请查看ASP.NET ImpersonationASP.NET Runtime Impersonation