簡體   English   中英

嘗試在Active Directory C#中委派OU的控件時,出現DirectoryServicesCOMException“發生操作錯誤”

[英]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
        }

方案詳細信息:

  1. Windows Server 2008 R2。
  2. 項目目標(.net 2.0)
  3. 我正在從通過LAN連接到服務器的計算機上運行代碼。
  4. 代碼不是asp.net代碼,而是本機c#代碼。

該代碼產生以下異常:

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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM