WebSecurity - RequireUser()
WebSecurity object
define
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)
Parameters
| Parameters | Type | Description |
|---|---|---|
| userID | Integer | The user ID |
| userName | String | Username |
Return Value
none.
Errors and exceptions
In the following cases, any access to the WebSecurity object will throw an InvalidOperationException:
- InitializeDatabaseConnection() The method is not called
- SimpleMembership Not initialized (or disabled in the website configuration)
Notes
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 the RequireRoles() method.
RequireUser() Allows only the specified user to access the web page. The recommended way to restrict page access is to create a role and use the RequireRoles() 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