THE WORLD'S LARGEST WEB DEVELOPER SITE
HTMLCSSJAVASCRIPTSQLPHPBOOTSTRAPJQUERYANGULARXML
 

WebSecurity - RequireUser()


WebSecurity Object WebSecurity Object

Definition

The RequireUser() method sets the HTTP status to 401 (Unauthorized) if the specified user is not logged on.


C# and VB Syntax

WebSecurity.RequireUser(userId)

or

WebSecurity.RequireUser(userName)

Parameters

Parameter Type Description
userID Integer The user ID
userName String The user name

Return Value

None.


Errors and Exceptions

Any access to the WebSecurity object throws an InvalidOperationException if:

  • The InitializeDatabaseConnection() method has not been called
  • SimpleMembership is not initialized (or disabled in the website configuration)

Remarks

RequireUser() verifies that the current user is the specified user.

To validate that the user is authenticated, use RequireAuthenticatedUser() instead.

To validate that a user is a member of a role (roles), use RequireRoles().

RequireUser() lets only the specified user access the web page. The recommended way to restrict access to a page is to create a role, and use the RequireRoles() method to verify that the user is a member of that role.


Technical Data

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

WebSecurity Object WebSecurity Object