WebSecurity Property - HasUserId
WebSecurity object
define
HasUserId The property is a Boolean value indicating whether the current user has WebSecurity a user ID in the database.
If the current user has a user ID, the property value is a Boolean value true. The default is false。
C# and VB syntax
WebSecurity.HasUserId
Example
Example C#
@{
bool value;
value=WebSecurity.HasUserId;
}
It is @value that the user has an ID
Example VB
@Code
Dim value as Boolean
value=WebSecurity.HasUserId
End Code
It is @value that the user has an ID
Notes
HasUserID The property is read-only. It cannot be changed through code.
HasUserId The property only verifies whether the user is WebSecurity has an ID in the database. It does not verify whether the user account is valid (confirmed), or whether the user is logged in.
Please use the IsConfirmed() method to verify whether the user has been confirmed.
Please use the IsAuthenticated property to verify whether the user is logged in.
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)
Technical data
| Name | Value |
|---|---|
| Namespace | WebMatrix.WebData |
| Assembly | WebMatrix.WebData.dll |
WebSecurity object