Met Websecurity Requireuser
# WebSecurity - RequireUser()
* * WebSecurity Object](#)
* * *
## Definition
If the specified user is not logged in, the **RequireUser()** method sets the HTTP status to 401 (Unauthorized).
* * *
## C# and VB Syntax
WebSecurity.RequireUser(userId)
or
WebSecurity.RequireUser(userName)
* * *
## Parameters
| Parameter | Type | Description |
| --- | --- | --- |
| _userID_ | Integer | User ID |
| _userName_ | String | User name |
* * *
## Return Value
None.
* * *
## Errors and Exceptions
In the following cases, any access to the **WebSecurity** object will throw an **InvalidOperationException**:
* The **InitializeDatabaseConnection()** method has not been called.
* **SimpleMembership** is not initialized (or is disabled in the 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 the **RequireRoles()** method.
**RequireUser()** only allows the specified user to access the web page. The recommended method to restrict page access is to create a role and use the **RequireRoles()** method to verify if the user is a member of that role.
* * *
## Technical Data
| Name | Value |
| --- | --- |
| Namespace | WebMatrix.WebData |
| Assembly | WebMatrix.WebData.dll |
* * WebSecurity Object](#)
YouTip