我想创建一种方法来查找用户是否具有针对特定“公司”的“角色”。
我的' UserRole '表包含' CompanyId '作为公司表的外键以及' UserId '和' RoleId '。
我正在努力实施一种方法,使用“ User.IsInCompanyRole(role,company)
”之类的符号作为' User.IsInRole
'方法。< / p>
请指导我。
答案 0 :(得分:1)
我找到了@Zoran提到的解决方案。现在不需要对我提出索赔。创建扩展方法就像一个魅力。 Extension Methods (C# Programming Guide)
这是我的延伸。
public static class Extention
{
public static bool IsInCompanyRole(this IPrincipal user, string role, int companyId)
{
// Code goes here
}
}
ans用法很简单,如
User.IsInEntityRole("Admin",1)