【发布时间】:2013-12-11 11:06:58
【问题描述】:
在我正在处理的一个 ASP.NET 项目中,我有几个角色由管理员在数据库中设置。我必须通过用户主体声明来比较这些角色。
目前我正在将所有 GroupSID 转换为相应的名称:
PrincipalContext ctx = new PrincipalContext(ContextType.Domain);
GroupPrincipal group = GroupPrincipal.FindByIdentity(ctx, IdentityType.Sid, sid);
if (_roleNames.Exists(r => string.CompareOrdinal(r, group.SamAccountName) == 0))
{
groupName = group.SamAccountName;
return true;
}
_roleNames 是包含角色的字符串列表。
_roleNames.Add("Read");
_roleNames.Add("Edit");
_roleNames.Add("Review");
_roleNames.Add("Publish");
问题是这个过程非常缓慢。主体来自 Active Directory,并且有很多声明。
有没有办法将我的应用程序中的角色名称转换为GroupSID,这样我基本上可以跳过将GroupSID 转换为他们的名字的过程?
伪代码:
list<string> roleSidList
foreach role in roleList
roleSidList.add(role.ConvertToSid())
foreach claim in Principal.Claims
if(roleSidList.Exists(r => r == claim))
// role exists, do something with it
【问题讨论】:
标签: asp.net asp.net-mvc-4 windows-authentication claims