WebSecurity Properties -CurrentUserId
WebSecurity Object
Definition
CurrentUserIdThe property is the current user'sWebSecurityID (primary key) in the database.
C# and VB Syntax
WebSecurity.CurrentUserId
Example
Example C#
@{
int value;
value=WebSecurity.CurrentUserId;
}
<p>Current User ID is: @value</p>
int value;
value=WebSecurity.CurrentUserId;
}
<p>Current User ID is: @value</p>
Example VB
@Code
Dim value as Integer
value=WebSecurity.CurrentUserId
End Code
<p>Current User ID is: @value</p>
Dim value as Integer
value=WebSecurity.CurrentUserId
End Code
<p>Current User ID is: @value</p>
Remarks
CurrentUserIdThe property is read-only. It cannot be changed through code.
This property is used to identifyWebSecuritythe user in the user profile table and membership table in the database.
Errors and Exceptions
If no user is currently logged in, thenCurrentUserIdthe property returns -1.
In the following cases, anyWebSecurityaccess to the object will throw anInvalidOperationException:
- InitializeDatabaseConnection()method is not called
- SimpleMembershipnot initialized (or disabled in website configuration)
Technical Data
| Name | Value |
|---|---|
| Namespace | WebMatrix.WebData |
| Assembly | WebMatrix.WebData.dll |
WebSecurity Object Other Extensions