WebSecurity CurrentUserName property
definition
CurrentUserName property is the name of the current user in the user profile database WebSecurity table.
C # and VB syntax
WebSecurity.CurrentUserName
Examples
Examples of C #
@{
string value;
value=WebSecurity.CurrentUserId;
}
<p>Welcome @value</p>
string value;
value=WebSecurity.CurrentUserId;
}
<p>Welcome @value</p>
Examples 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>
Remark
CurrentUserName property is read-only. It can not change the code.
Errors and exceptions
In the following scenario, any access to WebSecurity object will throw an InvalidOperationException:
- InitializeDatabaseConnection () method has not been called
- SimpleMembership not initialized (or disabled in the site configuration)
Technical data
名称 | 值 |
---|---|
Namespace | WebMatrix.WebData |
Assembly | WebMatrix.WebData.dll |
WebSecurity objects