O'Reilly logo

Professional ASP.NET 3.5 Security, Membership, and Role Management with C# and VB by Stefan Schackow, Bilal Haidar

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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); ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required