WebSecurity - RequireUser()
Definition
The RequireUser() method sets the HTTP status to 401 (Unauthorized) if the specified user is not logged in.
C# and VB Syntax
Parameters
Parameter | Type | Description |
---|---|---|
userID | Integer | 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:
The InitializeDatabaseConnection() method has not been called
SimpleMembership is not initialized (or disabled in the website configuration)
Remarks
RequireUser() verifies if the current user is the specified user.
To verify if the current user is authenticated, use the RequireAuthenticatedUser() method.
To verify if 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 |