【问题标题】:ASP.NET Core 2.2 GroupPrincipal.FindByIdentity no longer existsASP.NET Core 2.2 GroupPrincipal.FindByIdentity 不再存在
【发布时间】:2019-02-21 11:42:50
【问题描述】:

我正在尝试将用户添加到 AD 中的组,但是下面的示例代码不再有效:

UserPrincipal insUserPrincipal = (UserPrincipal)lbUsers.SelectedItem;
GroupPrincipal groupPrincipal = 
  GroupPrincipal.FindByIdentity(insPrincipalContext, group.GroupName);
if (groupPrincipal.Members.Contains(insPrincipalContext, 
    IdentityType.SamAccountName, insUserPrincipal.SamAccountName))
{
    MessageBox.Show(insUserPrincipal.Name + 
      " is already a member of group " + group.GroupName);
    return;
}
groupPrincipal.Members.Add(insUserPrincipal);
groupPrincipal.Save();

有谁知道如何在 asp.net core 2.2 中做到这一点?我找不到新版本。

GroupPrincipal.FindByIdentity(insPrincipalContext, group.GroupName); //No longer exists

编辑:我可以使用 GroupPrincipal 来搜索组等 - 但是缺少 FindByIdentity 方法

【问题讨论】:

    标签: c# .net-core active-directory


    【解决方案1】:

    为了在 .NET Core 上使用 System.DirectoryServices.AccountManagement,您需要安装提供此功能的 NuGet package with the same name。完成此操作后,您应该能够再次访问 GroupPrincipal 类型。

    【讨论】:

    • 嗨,我可以访问 GroupPrincipal 类型 - 但是似乎不再有一个名为 FindByIdentity 的方法?
    • @Hawke 有,你确定你看的是正确的GroupPrincipal 类型吗?你包括那个包裹吗?您使用的是什么目标框架,.NET Core?
    • 我正在使用包 System.DirectoryServices.AccountManagement 和 Core 2.2。 Visual Studio 引发错误,提示“类型名称 'FindByIdentity' 在类型 'GroupPrincipal '中不存在。
    • Nevernind - 它现在可以工作了(甚至看不出有什么区别..)
    猜你喜欢
    • 2019-06-15
    • 1970-01-01
    • 1970-01-01
    • 2019-08-09
    • 2019-05-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多