WebSecurity.RequireRoles Method
If the current user is not in all of the specified roles, sets the HTTP status code to 401 (Unauthorized).
Namespace: WebMatrix.WebData
Assembly: WebMatrix.WebData (in WebMatrix.WebData.dll)
Syntax
'Declaration
Public Shared Sub RequireRoles ( _
ParamArray roles As String() _
)
'Usage
Dim roles As String()
WebSecurity.RequireRoles(roles)
public static void RequireRoles(
params string[] roles
)
public:
static void RequireRoles(
... array<String^>^ roles
)
static member RequireRoles :
roles:string[] -> unit
public static function RequireRoles(
... roles : String[]
)
Parameters
- roles
Type: System.String[]
The roles to check. The current user must be in all of the roles that are passed in this parameter.
Exceptions
Exception | Condition |
---|---|
InvalidOperationException | The SimpleMembershipProvider.Initialize(String, NameValueCollection) method was not called. -or- The InitializeDatabaseConnection() method was not called. -or- The SimpleMembershipProvider membership provider is not registered in the configuration of your site. For more information, contact your site's system administrator. |
Remarks
This method validates that the user is a member of all of the specified roles. If the current user is not a member of all of the specified roles, the HTTP status is set to 401 (Unauthorized).
To validate that the user is authenticated, use the RequireAuthenticatedUser() method. To validate that the current user is a specific user (by user ID or by user name), use the RequireUser() method.