WebSecurity - RequireUser()
WebSecurity Object
Definition
If the specified user is not logged in,RequireUser()the method sets the HTTP status to 401 (Unauthorized).
C# and VB Syntax
WebSecurity.RequireUser(userId)
or
WebSecurity.RequireUser(userName)
or
WebSecurity.RequireUser(userName)
Parameters
| Parameters | Type | Description |
|---|---|---|
| userID | Integer | User ID |
| userName | String | Username |
Return Value
None.
Errors and Exceptions
In the following cases, any access toWebSecuritythe object will throw anInvalidOperationException:
- InitializeDatabaseConnection()the method has not been called
- SimpleMembershipnot initialized (or disabled in website configuration)
Remarks
RequireUser()Verifies whether the current user is the specified user.
To verify whether the current user is authenticated, use the RequireAuthenticatedUser()method.
To verify whether the user is a member of a role, use theRequireRoles()method.
RequireUser()Only allow the specified user to access the web page. The recommended way to restrict page access is to create a role and use theRequireRoles()method to verify whether the user is a member of that role.
Technical Data
| Name | Value |
|---|---|
| Namespace | WebMatrix.WebData |
| Assembly | WebMatrix.WebData.dll |
WebSecurity Object Other Extensions