Latest web development tutorials

WebSecurity HasUserId property

WebSecurity objects WebSecurity objects

definition

HasUserId attribute is a Boolean value that indicates whether the current user in the database WebSecurity whether the user ID.

If the current user has a user ID, the attribute value is a Boolean value true. The default is false.


C # and VB syntax

WebSecurity.HasUserId


Examples

Examples of C #

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

Examples VB

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

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


Remark

HasUserID property is read-only. It can not change the code.

HasUserId property only to verify whether the user has an ID in WebSecurity database. Does not verify that the user account is valid (to be confirmed), or whether the user has logged in.

Use IsConfirmed () method to verify that the user has been confirmed.

Use IsAuthenticated property to verify whether the user has logged in.


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)

Technical data

名称
Namespace WebMatrix.WebData
Assembly WebMatrix.WebData.dll


WebSecurity objects WebSecurity objects