简体   繁体   English

尝试在Active Directory C#中委派OU的控件时,出现DirectoryServicesCOMException“发生操作错误”

[英]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# 我正在尝试使用c#为Active Directory中的组织单位“委托控件”

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. Windows Server 2008 R2。
  2. project target (.net 2.0) 项目目标(.net 2.0)
  3. I am running code from my machine connected to the server via LAN. 我正在从通过LAN连接到服务器的计算机上运行代码。
  4. Code is NOT asp.net code , it`s native c# code. 代码不是asp.net代码,而是本机c#代码。

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 试试这个链接http://sanjaymungar.blogspot.com/2010/07/impersonation-in-aspnet-causes.html

add the code between 在之间添加代码

using (HostingEnvironment.Impersonate())           
{
   //your code
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 尝试从 Active Directory 检索和 OU,然后使用 C# 中的目录条目在 OU 上设置新属性 - Trying to Retrieve and OU from Active Directory, then set new properties on an OU using a Directory Entry in C# 尝试访问活动目录时出现DirectoryServicesCOMException(0x80072030) - DirectoryServicesCOMException (0x80072030) when trying to access active directory C#在Active Directory中创建OU - C# Create OU in Active Directory C#Active Directory,登录特定OU - C# Active Directory, Login in a specific OU C#和Active Directory:测试OU是否存在 - C# and Active Directory : test if an OU exist c#Active Directory…在根目录下创建OU时很奇怪 - c# Active Directory… weirdness when creating a OU just under the root 尝试从活动目录检索数据时发生操作错误 - An Operations Error Occured When trying to retrieve data from active directory 当我们在asp.net c#中的活动目录中创建用户时,如何在活动目录中嵌套OU时,如何给出路径来识别OU? - How to give path to identify OU when we have nested OU's in active directory while creating a user in active directory in asp.net c#? 使用C#在Active Directory中获取用户的父OU - Get parent OU of user in Active Directory using C# 使用具有层次结构的c#从活动目录获取OU列表 - Get OU list from active directory using c# with hierarchy
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM