[英]Trying to Retrieve and OU from Active Directory, then set new properties on an OU using a Directory Entry in C#
[英]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
}
方案详细信息:
该代码产生以下异常:
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.