
Usage of Roles API to Perform Authorization in .NETAuthentication and Authorization are two major dimensions of Security. Authentication is used to identify if the person logging in is a valid user. Authorization determines which all modules and actions are accessible to a particular User. Authorization has the following classifications:
User
Based Authorization determines if a module is accessible to a particular
user. This article
will focus on Role Based Authorization and how it can be achieved using
Roles API. What is
a Role? Users can
be grouped together into a common category called Roles. Few examples
to roles are: administrators, supervisors, managers. Administrators will
have different authorization permissions when compared to supervisors.
But all administrators will have the same permissions. In this case,
instead of configuring the same permission set across all administrator
users, you can group such Users into a role called administrator and define
permissions to the role instead of individual Users. You can add new users
or remove users from this role, based on which the corresponding permission
set mapped to the User will be modified. How to
Enable Role Based Authorization in Your .NET Application? If you want
to use Role Based Authorization in your application, make the following
entry in web.config file: The above
example contains only the property enabled of roleManager.
In addition, roleManager includes many other properties which are mentioned
below: ApplicationName:
Name of the application which maintains the role information. Here is an
example which uses most of the properties of RoleManager Tag in web.config
file: How to
Authorize Module for a Particular Role? Role manager
is now enabled in your application. Assume that you have created a role
called Supervisor. How do you define permission for Supervisor to access
files in a particular folder? You can do it by using <allow roles =
(role names comma separated)> inside your web.config file.
Heres an example: <configuration> As per this
example, only users with supervisor role and user named John can access
files from this location. How to
Manage Roles in Your Coding? You have
to create roles, assign users to roles and manage all role based activities.
How do you do that? You can perform role management in your coding using
methods of System.Web.Security.Roles class which represents the Roles
API. Given below are the methods provided by this class: CreateRole:
To create a new role. Heres
an example covering few of these methods: public void
manageRoles() { if (Roles.IsUserInRole("SupervisorRole"))
{ /*do corresponding code*/}
_______________________________________________________________________
FREE
Subscription
Subscribe
to our mailing list and receive new articles Note
: We never rent, trade, or sell my email lists to Visit
.NET Programming Tutorial Homepage ______________________________________________________ |