WebSecurity Property - CurrentUserName
WebSecurity object
define
CurrentUserName The property is the current user's WebSecurity The name in the user profile table in the database.
C# and VB syntax
WebSecurity.CurrentUserName
Example
Example C#
@{
string value;
value=WebSecurity.CurrentUserId;
}
Welcome @value
Example VB
@Code
Dim value as String
value=WebSecurity.CurrentUserName
End Code
Welcome @value
Notes
The **CurrentUserName ** property is read-only. It cannot be changed through code.
Errors and exceptions
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