こんにちは、Active Directory ユーザーのパスワードをリセットしようとしていますが、エラーが発生しています。コードは次のとおりです。
public string ChangePassword(string Identity,string OldPassword, string Password)
{
string success = "Success";
try
{
DirectoryEntry UserEntry = null;
DirectoryEntry entry = new DirectoryEntry("LDAP://.../DC=Domain,DC=COM", Identity, OldPassword);
DirectorySearcher search = new DirectorySearcher(entry);
SearchResult resultsearch = search.FindOne();
if (resultsearch == null)
{
success = "User Not Found In This Domain";
}
else
{
success = "find";
UserEntry = resultsearch.GetDirectoryEntry();
UserEntry.Username = @"Domain\Administrator";
UserEntry.Password = "password";
UserEntry.AuthenticationType = AuthenticationTypes.None;
if (UserEntry == null)
success = "User Not Found In This Domain";
else
{
try
{
success = UserEntry.Username.ToString();
UserEntry.Invoke("ChangePassword", new object[] { OldPassword, Password });
UserEntry.CommitChanges();
}
catch (Exception ex)
{
success = ex.ToString();
}
}
}
}
catch (Exception ex)
{
success = ex.ToString();
}
したがって、UserEntry.Invoke("ChangePassword", new object[] { OldPassword, Password }); でエラーが発生しています。UserEntry.CommitChanges();
エラー:
System.Runtime.InteropServices.COMException (0x80020006): Unknown name. (Exception from HRESULT: 0x80020006 (DISP_E_UNKNOWNNAME))
at System.DirectoryServices.DirectoryEntry.Invoke(String methodName, Object[] args)
at WebService.ChangePassword(String Identity, String OldPassword, String Password) in c:\inetpub\wwwroot\WebSite1\App_Code\WebService.cs:line 370