Export (0) Print
Expand All

WebSecurity.RequireUser Method (Int32)

If the specified user is not logged on, sets the HTTP status to 401 (Unauthorized).

Namespace:  WebMatrix.WebData
Assembly:  WebMatrix.WebData (in WebMatrix.WebData.dll)

'Declaration
Public Shared Sub RequireUser ( _
	userId As Integer _
)
'Usage
Dim userId As Integer

WebSecurity.RequireUser(userId)

Parameters

userId
Type: System.Int32
The ID of the user to compare.

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 verifies that the current user is the specified user. If the current user is not the specified user, the HTTP status is set to 401 (Unauthorized).

To validate that the user is authenticated, use the RequireAuthenticatedUser method. To validate that a user is a member of a role or set of roles, use the RequireRoles(String()) method.

NoteNote:

This method will let only the specified user access the web page. The recommended way to restrict access to a web page is to create a role, and then use the RequireRoles(String()) method to verify that the current user is a member of that role.

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