我在Active Directory中的單獨服務器中有一個Web應用程序,我想更改用戶密碼。該代碼是下一個:活動目錄 - 調用的目標已拋出異常
string newPassword = Membership.GeneratePassword(int.Parse(WebConfigurationManager.AppSettings["passLenght"]),
int.Parse(WebConfigurationManager.AppSettings["passNonAlpha"]));
DirectoryEntry de = new DirectoryEntry(WebConfigurationManager.ConnectionStrings["ADConnString"].ConnectionString,
WebConfigurationManager.AppSettings["ADAdmin"], WebConfigurationManager.AppSettings["ADAdminPass"]);
DirectorySearcher deSearch = new DirectorySearcher(de);
deSearch.Filter = "(&(objectClass=user) (userPrincipalName=" + name + "))";
SearchResultCollection results = deSearch.FindAll();
if (results.Count == 1)
{
foreach (SearchResult OneSearchResult in results)
{
DirectoryEntry AlterUser = OneSearchResult.GetDirectoryEntry();
AlterUser.AuthenticationType = AuthenticationTypes.Secure;
AlterUser.Invoke("SetPassword", newPassword);
AlterUser.CommitChanges();
AlterUser.Close();
}
}
當我在開發環境中運行這個(其中Active Directory和Web應用程序在同一臺服務器上),這是工作。但是,當我嘗試在生產環境中我遇到了一個錯誤運行:
Exception has been thrown by the target of an invocation
我缺少什麼?
謝謝。
編輯:
我能去的異常錯誤深,我得到這個:
Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))
請您能不能給我們ADConnString'的'形式在配置文件中。你能有更多關於異常的細節(哪條指令導致它)。 – JPBlanc
什麼行引發異常?調用?的CommitChanges?過濾?您的搜索是否返回任何條目? – Peter
對不起,我不能給你連接字符串的安全問題。但是,我可以告訴你它正在通過成員資格配置工作。現在我不能告訴你它是導致錯誤的行或命令,我會嘗試調試它,當我可以...記住它是一個生產環境... – Bargant