Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

WebSecurity CurrentUserId Property

WebSecurity Property - CurrentUserId


WebSecurity Object WebSecurity object


define

CurrentUserId The property is the current user's WebSecurity ID (primary key) in the database.


C# and VB syntax

WebSecurity.CurrentUserId


Example

Example C#

@{

int value;

value=WebSecurity.CurrentUserId;

}

Current User ID is: @value

Example VB

@Code

Dim value as Integer

value=WebSecurity.CurrentUserId

End Code

Current User ID is: @value


Notes

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

This property is used to identify WebSecurity users in the user profile table and the membership table in the database.


Errors and exceptions

If no user is currently logged in, then CurrentUserId the property returns -1.

In the following cases, any access to the WebSecurity object will throw an InvalidOperationException:


Technical data

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

WebSecurity Object WebSecurity object