WebSecurity Properties -CurrentUserName
WebSecurity Object
Definition
CurrentUserNameThe property is the current user'sWebSecurityname in the user profile table in the database.
C# and VB Syntax
WebSecurity.CurrentUserName
Example
Example C#
@{
string value;
value=WebSecurity.CurrentUserId;
}
<p>Welcome @value</p>
string value;
value=WebSecurity.CurrentUserId;
}
<p>Welcome @value</p>
Example VB
@Code
Dim value as String
value=WebSecurity.CurrentUserName
End Code
<p>Welcome @value</p>
Dim value as String
value=WebSecurity.CurrentUserName
End Code
<p>Welcome @value</p>
Remarks
CurrentUserName The property is read-only. It cannot be changed through code.
Errors and Exceptions
In the following cases, anyWebSecurityaccess to the object will throw anInvalidOperationException:
- InitializeDatabaseConnection()The method has not been called.
- SimpleMembershipnot initialized (or disabled in the website configuration)
Technical Data
| Name | Value |
|---|---|
| Namespace | WebMatrix.WebData |
| Assembly | WebMatrix.WebData.dll |
WebSecurity Object Other Extensions