Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All

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)

public static function RequireRoles(
	... roles : String[]


Type: System.String[]
The roles to check. The current user must be in all of the roles that are passed in this parameter.


The SimpleMembershipProvider.Initialize(String, NameValueCollection) method was not called.


The InitializeDatabaseConnection() method was not called.


The SimpleMembershipProvider membership provider is not registered in the configuration of your site. For more information, contact your site's system administrator.

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.

  • Medium trust for the immediate caller. This member can be used by partially trusted code.
© 2015 Microsoft