[英]Trying to Retrieve and OU from Active Directory, then set new properties on an OU using a Directory Entry in C#
[英]DirectoryServicesCOMException “operations error occurred” when trying to delegate control for OU in Active directory C#
我正在嘗試使用c#為Active Directory中的組織單位“委托控件”
我正在使用以下代碼:
try
{
using (DirectoryEntry deOU = new DirectoryEntry("LDAP://MYDOMAIN/OU=MYOU", "admin_user_on_domain", "password"))
{
NTAccount acctUser = new NTAccount("some_user");
ActiveDirectoryAccessRule ruleReadWriteProp = new ActiveDirectoryAccessRule((IdentityReference)acctUser, ActiveDirectoryRights.GenericAll, AccessControlType.Allow);
deOU.ObjectSecurity.AddAccessRule(ruleReadWriteProp);
deOU.Options.SecurityMasks = SecurityMasks.Dacl;
deOU.CommitChanges();
Console.Write("DONE");
}
}
catch (Exception ex)
{
//Do something with exception
}
方案詳細信息:
該代碼產生以下異常:
System.DirectoryServices.DirectoryServicesCOMException
Message: An operations error occurred.
我試圖直接在服務器上運行代碼,出現相同的異常,請指教謝謝
試試這個鏈接http://sanjaymungar.blogspot.com/2010/07/impersonation-in-aspnet-causes.html
在之間添加代碼
using (HostingEnvironment.Impersonate())
{
//your code
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.