WebSecurity Property - CurrentUserId
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:
- InitializeDatabaseConnection() The method is not called
- SimpleMembership Not initialized (or disabled in the website configuration)
Technical data
| Name | Value |
|---|---|
| Namespace | WebMatrix.WebData |
| Assembly | WebMatrix.WebData.dll |
WebSecurity object