我正在尝试让我自己的静态类与 AD 一起使用。我写了一个静态方法:
public static void AddReadingAceForGroup(DirectoryEntry dirEntry, string groupName)
{
dirEntry.RefreshCache();
DirectoryEntry root = new DirectoryEntry("LDAP://192.168.1.1/ dc=mydomain,dc=ru");
using (DirectorySearcher ds = new DirectorySearcher(root, "CN="+groupName))
{
SearchResult sr = ds.FindOne();
root = sr.GetDirectoryEntry();
}
try
{
ActiveDirectoryAccessRule accessRule =
new ActiveDirectoryAccessRule(root.ObjectSecurity.GetGroup(typeof(SecurityIdentifier)),
ActiveDirectoryRights.GenericRead, AccessControlType.Allow);
dirEntry.ObjectSecurity.AddAccessRule(accessRule);
dirEntry.CommitChanges();
}
catch(Exception e)
{
}
}
在使用此功能之前,我使用远程凭据模拟用户,然后代码正常工作,但没有结果。删除 ACE 的类似功能可以正常工作。