简体   繁体   中英

DirectoryServicesCOMException “operations error occurred” when trying to delegate control for OU in Active directory C#

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:

  1. Windows server 2008 R2.
  2. project target (.net 2.0)
  3. I am running code from my machine connected to the server via LAN.
  4. Code is NOT asp.net code , it`s native c# code.

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM