WebSecurity RequireUser method
definition
If the specified user is not logged, RequireUser () method sets the HTTP status of 401 (Unauthorized).
C # and VB syntax
WebSecurity.RequireUser(userId)
or
WebSecurity.RequireUser(userName)
or
WebSecurity.RequireUser(userName)
parameter
参数 | 类型 | 描述 |
---|---|---|
userID | Integer | 用户 ID |
userName | String | 用户名 |
return value
no.
Errors and exceptions
In the following scenario, any access to WebSecurity object will throw an InvalidOperationException:
- InitializeDatabaseConnection () method has not been called
- SimpleMembership not initialized (or disabled in the site configuration)
Remark
RequireUser () Verify that the current user is the user specified.
To verify whether the current user has been authenticated, use RequireAuthenticatedUser () method.
To verify that the user is a member of a role, use RequireRoles () method.
RequireUser () allow only specified users to access Web pages. Restrict access page proposal is to create a character, and use RequireRoles () method to verify whether the user is a member of the role.
Technical data
名称 | 值 |
---|---|
Namespace | WebMatrix.WebData |
Assembly | WebMatrix.WebData.dll |
WebSecurity objects