TUTORIALBackendFETCHED
WebSecurity 属性 - CurrentUserName
WebSecurity 属性 - CurrentUserName WebSecurity 对象 定义 CurrentUserName 属性是当前用户在 WebSecurity 数据库中用户资料表中的名称。 C# 和 VB 语法 WebSecurity.CurrentUserName 实例 实例 C# @{ string value; value=WebSecurity.CurrentUserId; } &..
Updated 7/16/2026
Tutorial detail pages default to noindex.
WebSecurity 属性 - CurrentUserName
WebSecurity 对象
定义
CurrentUserName 属性是当前用户在 WebSecurity 数据库中用户资料表中的名称。
C# 和 VB 语法
WebSecurity.CurrentUserName
实例
实例 C#
@{
string value;
value=WebSecurity.CurrentUserId;
}
<p>Welcome @value</p>
string value;
value=WebSecurity.CurrentUserId;
}
<p>Welcome @value</p>
实例 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>
备注
CurrentUserName 属性是只读的。它不能通过代码更改。
错误和异常
在下面的情况下,任何对 WebSecurity 对象的访问将抛出一个 InvalidOperationException:
- InitializeDatabaseConnection() 方法没有被调用
- SimpleMembership 没有初始化(或者在网站配置中禁用)
技术数据
| 名称 | 值 |
|---|---|
| Namespace | WebMatrix.WebData |
| Assembly | WebMatrix.WebData.dll |
WebSecurity 对象