我正在尝试检查用户是否是以下组的成员:
if (conditionalGroup != null)
{
if (!currentUser.IsMemberOf(conditionalGroup))
{
_logger.Debug("Adding user to Specific group.");
conditionalGroup.Members.Add(currentUser);
conditionalGroup.Save();
}
conditionalGroup.Dispose();
}
但是它失败了:An error (1789) occurred while enumerating the group membership. The member's SID could not be resolved.
该组是本地计算机上的用户组。我也对 IIS_IUSRS 组做同样的事情,那个很好。这只是今天在我的构建机器上开始的,并且以前一直有效。这是一个错误还是我做错了什么?
这是我创建用户的方式:
pc = new PrincipalContext(ContextType.Machine); currentUser = UserPrincipal.FindByIdentity(pc, u.UserName);
if (currentUser == null)
{
currentUser = new UserPrincipal(pc)
{
Name = u.UserName,
Description = u.UserDescription,
UserCannotChangePassword = false,
PasswordNeverExpires = true
};
currentUser.SetPassword(u.UserPassword);
currentUser.Save();
}