System.Web.Security Namespace
.NET Framework version 2.0
Manages user membership in roles for authorization checking in an ASP.NET application. This class cannot be inherited.
Visibility |
Name |
Parameters |
Return Type |
public static |
AddUsersToRole |
(
String
usernames
,
String
roleName
)
|
Void
|
public static |
AddUsersToRoles |
(
String
usernames
,
String
roleNames
)
|
Void
|
public static |
AddUserToRole |
(
String
username
,
String
roleName
)
|
Void
|
public static |
AddUserToRoles |
(
String
username
,
String
roleNames
)
|
Void
|
public static |
CreateRole |
(
String
roleName
)
|
Void
|
public static |
DeleteCookie |
( )
|
Void
|
public static |
DeleteRole |
(
String
roleName
)
|
Boolean
|
public static |
DeleteRole |
(
String
roleName
,
Boolean
throwOnPopulatedRole
)
|
Boolean
|
public static |
FindUsersInRole |
(
String
roleName
,
String
usernameToMatch
)
|
String
|
public static |
GetAllRoles |
( )
|
String
|
public static |
GetRolesForUser |
(
String
username
)
|
String
|
public static |
GetRolesForUser |
( )
|
String
|
public static |
GetUsersInRole |
(
String
roleName
)
|
String
|
public static |
IsUserInRole |
(
String
roleName
)
|
Boolean
|
public static |
IsUserInRole |
(
String
username
,
String
roleName
)
|
Boolean
|
public static |
RemoveUserFromRole |
(
String
username
,
String
roleName
)
|
Void
|
public static |
RemoveUserFromRoles |
(
String
username
,
String
roleNames
)
|
Void
|
public static |
RemoveUsersFromRole |
(
String
usernames
,
String
roleName
)
|
Void
|
public static |
RemoveUsersFromRoles |
(
String
usernames
,
String
roleNames
)
|
Void
|
public static |
RoleExists |
(
String
roleName
)
|
Boolean
|
|
ASP.NET role management enables you to manage authorization for your application based on groups of users, referred to as roles. By assigning users to roles, you can control access to different parts or features of your Web application based on role instead of, or in addition to, specifying authorization based on user name. For example, an employee application might have roles such as Managers, Employees, Directors, and so on, where different privileges are specified for each role.
Users can belong to more than one role. For example, if your site is a discussion forum, some users might be in the role of both Members and Moderators. You might define each role to have different privileges on the site, and a user who is in both roles would then have both sets of privileges.
To enable role management for your ASP.NET application, use the roleManager element of the system.web section in the Web.config file for your application, as shown in the following example.
<configuration>
<connectionStrings>
<add name = "SqlServices" connectionString=
"Data Source=localhost;Initial Catalog=aspnetdb;Integrated Security=SSPI;" />
</connectionStrings>
<system.web>
<authentication mode = "Forms" >
<forms loginUrl = "login.aspx"
name = ".ASPXFORMSAUTH" />
</authentication>
<roleManager defaultProvider = "SqlProvider"
enabled = "true"
cacheRolesInCookie = "true"
cookieName = ".ASPROLES"
cookieTimeout = "30"
cookiePath = "/"
cookieRequireSSL = "false"
cookieSlidingExpiration = "true"
cookieProtection = "All" >
<providers>
<add
name = "SqlProvider"
type = "System.Web.Security.SqlRoleProvider"
connectionStringName = "SqlServices"
applicationName = "SampleApplication" />
</providers>
</roleManager>
</system.web>
</configuration>
RoleManagerModule Class roleManager Section