X
HOME HTML CSS JAVASCRIPT SQL PHP JQUERY XML ASP.NET MORE...
REFERENCES | EXAMPLES | FORUM | ABOUT

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

Your suggestion:

Close [X]

Thank You For Helping Us!

Your message has been sent to W3Schools.

Close [X]
Search w3schools.com:

WEB BUILDING

Download XML Editor FREE Website BUILDER Free HTML5 Templates FREE Website Templates Free HTML Templates

SHARE THIS PAGE

facebook