I am trying to "Delegate control" for Organizational Unit in Active Directory using c#
I am using the following code:
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
}
The scenario details:
The code produces the following exception :
System.DirectoryServices.DirectoryServicesCOMException
Message: An operations error occurred.
I tried to run the code Directly on the server ,, the same exception appear , please advice thanks
try this link http://sanjaymungar.blogspot.com/2010/07/impersonation-in-aspnet-causes.html
add the code between
using (HostingEnvironment.Impersonate())
{
//your code
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.