【发布时间】:2020-05-08 13:11:26
【问题描述】:
我正在尝试使用 MVC C# LDAP 更新 Active Directory 上的用户,如果用户已经在组中,我首先将他从组中删除,然后使用 Principal 上下文再次添加他。我尝试在删除循环结束时提交更改,但这没有帮助
这是我的代码删除代码:
PropertyValueCollection groups = result.GetDirectoryEntry().Properties["memberOf"];
if (groups != null)
{
for (int i = 0; i < groups.Count; i++)
{
string groupDn = (string)groups[i];
DirectoryEntry group = new DirectoryEntry("LDAP://" + groupDn, null, null);
if (group != null)
{
group.Invoke("Remove", new object[] { result.Path });
}
group.CommitChanges();
}
}
将用户添加到组的代码
//DirectoryEntry dirEntry = new DirectoryEntry(groupDirectoryEntry);
using (PrincipalContext pc = new PrincipalContext(ContextType.Domain, AD_Address))// "10.125.153.30"))
{
foreach (var rights in accessGroupList)
{
GroupPrincipal group = GroupPrincipal.FindByIdentity(pc, rights);
group.Members.Add(pc, IdentityType.UserPrincipalName, model.validPersalNumber); //this is where is failes
group.Save();
}
}
【问题讨论】:
-
我很好奇:为什么要将用户从组中删除,然后将其添加回同一组?
-
@GabrielLuci 我有一个界面,呼叫中心代理必须选择访问(例如国家、省、国家、自己的部门)级别和应用程序(财务、人力资源、报告),所以在某些情况下你可能发现他们想要撤销访问或编辑权限。当我用谷歌搜索解决方案时,大多数解决方案都建议我从组中删除用户并再次添加他。
-
删除和重新添加到同一个组不会有任何影响 - 至少在 AD 本身中没有。您是否有其他应用程序正在读取组成员身份并在您删除和重新添加组时以某种方式重置?
-
不确定我是否很好地理解了这个问题,但是我们有一个 Web 应用程序,人们使用 AD 详细信息登录并根据他们在 AD 和应用程序中拥有的访问权限授予他们访问文件的权限。我还是 AD 新手,所以我对 AD 了解的信息很少
标签: c# asp.net-mvc active-directory ldap-query principalcontext