我的目标是获取当前用户的AD组,如果它们与dbset模型匹配,则仅显示此类项目。
UserPrincipal cuser = UserPrincipal.FindByIdentity(pcontext, User.Identity.Name);
var ugroups = cuser.GetAuthorizationGroups().Select(s => s.Name);
var sites = new List<Site>();
if (cuser != null)
{
if (IsGroupMember(cuser.ToString(), "AD_Group"))
{
//This works as intended, the entire list is displayed.
sites = _context.Sites.ToList();
}
else
{
//This doesn't work and where i'm trying to make the comparison.
sites = _context.Sites.Where(w => w.Name = ugroups).ToList();
}
}
这是站点模型:
public class Site
{
public int Id { get; set; }
public string Name { get; set; }
public string SiteAbbreviation { get; set; }
}
答案 0 :(得分:2)
我认为这是您想要的:
Signature
这将为您提供一个站点列表,其中站点名称与组之一匹配。