Easy Tutorial
❮ Control Rangevalidator Prop Webcontrol Bulletedlist Bulletstyle ❯

WebSecurity - RequireRoles()


Definition

The RequireRoles() method sets the HTTP status to 401 (Unauthorized) if the current user is not a member of all specified roles.


C# and VB Syntax


Examples

Example C

Example VB


Parameters

Parameter Type Description
roles String A comma-separated list of roles that the current user must belong to.

Return Value

None.


Errors and Exceptions

Under the following conditions, any access to the WebSecurity object will throw an InvalidOperationException:


Remarks

RequireRoles() verifies whether the current user is a member of all specified roles. If the current user is not a member of all specified roles, the HTTP status is set to 401 (Unauthorized).

To verify if the current user is authenticated, use the RequireAuthenticatedUser() method.

To verify if the current user is the specified user, use the RequireUser() method.


Technical Data

Name Value
Namespace WebMatrix.WebData
Assembly WebMatrix.WebData.dll

❮ Control Rangevalidator Prop Webcontrol Bulletedlist Bulletstyle ❯