WebSecurity Property - HasUserId


❮ 网络安全

定义

HasUserId 属性是一个布尔值,指示当前用户在 WebSecurity 数据库中是否有用户 ID。

如果当前用户有用户 ID,则属性值为布尔值 true。 默认为 false


C# 和 VB 语法

WebSecurity.HasUserId

实例

实例 C#

@{
bool value;
value=WebSecurity.HasUserId;
}
<p>It is @value that the user has an ID</p>

实例 VB

@Code
Dim value as Boolean
value=WebSecurity.HasUserId
End Code

<p>It is @value that the user has an ID</p>

备注

HasUserID 属性是只读的。 无法通过代码更改。

HasUserId 属性仅验证用户在 WebSecurity 数据库中是否具有 ID。 它不会验证用户帐户是否有效(已确认),或者用户是否已登录。

使用 IsConfirmed() 方法来验证用户是否被确认。

使用 IsAuthenticated 属性来验证用户是否已登录。


错误和异常

在以下情况下,对 WebSecurity 对象的任何访问都会引发 InvalidOperationException

  • InitializeDatabaseConnection()方法没有被调用
  • SimpleMembership 未初始化(或在网站配置中禁用)

❮ 网络安全