I’m implementing a custom IPrincipal that I want to use across multiple applications.
I have 2 questions about the IsInRole method…
1) Is it recommended that I use a custom RoleProvider with the custom IPrincipal? I could always put the logic that checks the users roles in the class that inherits from IPrincipal.
Something like:
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) Because I want to use this across multiple MVC3 applications. Where is the best place to store the application name? I need to be able to set this manually.
public bool IsInRole(string role)
{
string applicationName = [where can I store this globally for my asp.net mvc3 app]
return AreTheyInARoleForThisApplication(applicationName, role);
}
I’d say you are free to use whatever technique you want in order to find out if a use is in a role. A RoleProvider isn’t a must here.
Can’t you pass on the application name as a constructor parameter then store it in a member?