WebSecurity - RequireUser()
The RequireUser() method sets the HTTP status to 401 (Unauthorized) if the specified user is not logged on.
C# and VB Syntax
|userID||Integer||The user ID|
|userName||String||The user name|
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)
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.