我用下面的代碼在Active Directory爲什麼我得到了「訪問被拒絕(異常來自HRESULT:0X80070005(E_ACCESSDENIED))」在Active Directory中創建用戶時
DirectoryEntry newUser = null;
try
{
if (!Authenticate()) return null;
newUser = location.Children.Add("CN=" + userName, "user");
newUser.Properties["samAccountName"].Value = userName;
newUser.Properties["cn"].Value = userName;
newUser.CommitChanges();
string guid = newUser.Guid.ToString();
newUser.Invoke("SetPassword", new object[] { password });
newUser.CommitChanges();
DomainDirectoryEntry.Close();
newUser.Close();
return guid;
}
catch
{
throw;
}
finally
{
newUser = null;
}
創建用戶如果我運行這個來自asp.net網頁的代碼,它創建用戶在Active Directory中,它創建禁用,但它會拋出異常Exception has been thrown by the target of an invocation.
,當我得到這個異常的內部異常它讓我Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDEN
我敢肯定,我用來訪問活動帳戶目錄是一個完整的管理..
我不確定的原因,爲什麼它是創建用戶,但它在設置密碼時產生錯誤...可以引導我得到錯誤嗎?
但應用程序池的用戶甚至影響我使用域管理員用戶從代碼訪問活動目錄... – 2010-08-08 07:17:16