C# Role Provider for multiple applications
        Posted  
        
            by 
                Juventus18
            
        on Programmers
        
        See other posts from Programmers
        
            or by Juventus18
        
        
        
        Published on 2012-09-17T23:08:58Z
        Indexed on 
            2012/09/18
            3:52 UTC
        
        
        Read the original article
        Hit count: 458
        
I'm making a custom RoleProvider that I would like to use across multiple applications in the same application pool. For the administration of roles (create new role, add users to role, etc..) I would like to create a master application that I could login to and set the roles for each additional application. So for example, I might have AppA and AppB in my organization, and I need to make an application called AppRoleManager that can set roles for AppA and AppB. I am having troubles implementing my custom RoleProvider because it uses an initialize method that gets the application name from the config file, but I need the application name to be a variable (i.e. "AppA" or "AppB") and passed as a parameter. I thought about just implementing the required methods, and then also having additional methods that pass application name as a parameter, but that seems clunky. i.e.
public override CreateRole(string roleName)
{
  //uses the ApplicationName property of this, which is set in web.config
  //creates role in db
}
public CreateRole(string ApplicationName, string roleName)
{
  //creates role in db with specified params.
}
Also, I would prefer if people were prevented from calling CreateRole(string roleName) because the current instance of the class might have a different applicationName value than intended (what should i do here? throw NotImplementedException?).
I tried just writing the class without inheriting RoleProvider. But it is required by the framework.
Any general ideas on how to structure this project?
I was thinking make a wrapper class that uses the role provider, and explicitly sets the application name before (and after) and calls to the provider something like this:
static class RoleProviderWrapper
{
  public static CreateRole(string pApplicationName, string pRoleName)
  {
    Roles.Provider.ApplicationName = pApplicationName;
    Roles.Provider.CreateRole(pRoleName);
    Roles.Provider.ApplicationName = "Generic";
  }
}
is this my best-bet?
© Programmers or respective owner