【发布时间】:2012-07-25 09:22:53
【问题描述】:
我正在实现一个自定义的IPrincipal,我想在多个应用程序中使用它。
我有两个关于IsInRole 方法的问题...
1) 是否建议我将自定义 RoleProvider 与自定义 IPrincipal 一起使用?我总是可以将检查用户角色的逻辑放在从 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);
}
【问题讨论】:
标签: c# asp.net-mvc-3 roleprovider