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 void RequireRoles(
	params string[] roles
)

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.

ExceptionCondition
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.

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.
Show:
© 2014 Microsoft