我正在实现我想跨多个应用程序使用自定义IPrincipal
。 我有关于IsInRole
方法的2个问题...自定义IPrincipal与应用程序名称IsInRole
1)是否建议我使用自定义的的RoleProvider?我总是可以将检查用户角色的逻辑放在从IPrincipal继承的类中。
喜欢的东西:
public class SSDSPrincipal : IPrincipal
{
public SSDSPrincipal(SSDSIdentity identity)
{
this.Identity = identity;
}
public IIdentity Identity {get;private set;}
public bool IsInRole(string role)
{
string[] roles = Roles.Providers["SSDSRoleProvider"].GetRolesForUser(Identity.Name);
return roles.Any(s => role.Contains(s));
}
}
2)因为我想在多个MVC3应用程序使用此。哪里是存储应用程序名称的最佳位置?我需要能够手动设置。
public bool IsInRole(string role)
{
string applicationName = [where can I store this globally for my asp.net mvc3 app]
return AreTheyInARoleForThisApplication(applicationName, role);
}
适当的地方,我想我会尽量避免使用自定义角色提供程序即可。检查用户是否是角色是我真正需要的唯一功能。传入应用程序名称听起来不错...谢谢:) – woggles 2012-07-25 09:30:20