1

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

4

1 回答 1

0

试试这个链接http://sanjaymungar.blogspot.com/2010/07/impersonation-in-aspnet-causes.html

之间添加代码

using (HostingEnvironment.Impersonate())           
{
   //your code
}
于 2013-07-02T17:25:10.530 回答