14.4. RoleProvider

As with the Membership feature, Role Manager depends heavily on providers. In fact, the major pieces of functionality within the Role Manager feature are effectively implemented in RoleManagerModule, RolePrincipal and concrete implementations of the RoleProvider base class. Because Role Manager does not have an object model for a role, the RoleProvider definition is pretty simple. Roles are just strings, and the users associated with those roles are also just strings. As a result, the RoleProvider base class is just an abstract class definition. Unlike MembershipProvider, RoleProvider does not have any helper methods or private methods implementing base portions of the Role Manager feature.

C#

public abstract class RoleProvider : ProviderBase { //Properties public abstract string ApplicationName { get; set; } //Authorization related methods public abstract bool IsUserInRole(string username, string roleName); //Methods that deal with fetching a user's role information public abstract string[] GetRolesForUser(string username); //Methods for creating, deleting and managing roles public abstract void CreateRole(string roleName); public abstract bool DeleteRole(string roleName, bool throwOnPopulatedRole); public abstract bool RoleExists(string roleName); public abstract void AddUsersToRoles(string[] usernames, string[] roleNames); public abstract void RemoveUsersFromRoles(string[] usernames, string[] roleNames); public abstract string[] GetUsersInRole(string roleName); ...

Get Professional ASP.NET 3.5 Security, Membership, and Role Management with C# and VB now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.