I am trying to build a self-service password reset tool for a test domain. I am using ASP.NET 4 and IIS 7.
My code:
string userDirectoryEntry = "WinNT://domain/" + usermapping[user[1]]
System.DirectoryServices.DirectoryEntry ADEntryToReset = new System.DirectoryServices.DirectoryEntry(userDirectoryEntry);
ADEntryToReset.Invoke("SetPassword", new object[] { newPassword });
ADEntryToReset.Properties["passwordExpired"][0] = 1;
ADEntryToReset.CommitChanges();
However I am getting access denied when committing the password change. I have changed the Default App Pool to run under an admin account that can change passwords. Works fine in the Visual Studio debugger.
I have also tried explicitly supplying credentials to the DirectoryEntry object (msdn). This also does not work.
Any ideas?