C# Role Provider for multiple applications
- by Juventus18
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?