Latest web development tutorials

WebSecurity CurrentUserId property

WebSecurity objects WebSecurity objects

definition

CurrentUserId attribute is the current user ID (primary key) in WebSecurity database.


C # and VB syntax

WebSecurity.CurrentUserId


Examples

Examples of C #

@{
int value;
value=WebSecurity.CurrentUserId;
}

<p>Current User ID is: @value</p>

Examples VB

@Code
Dim value as Integer
value=WebSecurity.CurrentUserId
End Code

<p>Current User ID is: @value</p>


Remark

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

This attribute is used to identify users in a database table WebSecurity members and users in the table.


Errors and exceptions

If no user is currently logged on, CurrentUserId property returns -1.

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