我正在尝试使用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
}
方案详情:
代码产生以下异常:
System.DirectoryServices.DirectoryServicesCOMException
Message: An operations error occurred.
我试图在服务器上直接运行代码,出现同样的异常,请指教 感谢
答案 0 :(得分:0)
尝试此链接http://sanjaymungar.blogspot.com/2010/07/impersonation-in-aspnet-causes.html
在
之间添加代码using (HostingEnvironment.Impersonate())
{
//your code
}