WebSecurity Properties - HasUserId


WebSecurity 对象WebSecurity Object

Definition

HasUserIdThe property is a Boolean value that indicates whether the current userWebSecurityhas a user ID in the database.

If the current user has a user ID, the property value is a Boolean valuetrue. The default isfalse。


C# and VB Syntax

WebSecurity.HasUserId


Example

Example C#

@{
bool value;
value=WebSecurity.HasUserId;
}
<p>It is @value that the user has an ID</p>

Example VB

@Code
Dim value as Boolean
value=WebSecurity.HasUserId
End Code

<p>It is @value that the user has an ID</p>


Remarks

HasUserIDThe property is read-only. It cannot be changed through code.

HasUserIdThe property only verifies whether the userWebSecurityhas an ID in the database. It does not verify whether the user account is valid (confirmed), or whether the user is logged in.

Please useIsConfirmed()method to verify whether the user has been confirmed.

Please useIsAuthenticatedproperty to verify whether the user is logged in.


Errors and Exceptions

In the following cases, anyWebSecurityaccess to the object will throw anInvalidOperationException:

  • InitializeDatabaseConnection()method has not been called
  • SimpleMembershipnot initialized (or disabled in website configuration)

Technical Data

Name Value
Namespace WebMatrix.WebData
Assembly WebMatrix.WebData.dll


WebSecurity 对象WebSecurity Object Other Extensions