WebSecurity 屬性 - 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>
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>
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 沒有初始化(或者在網站配置中禁用)
技術數據
名稱 | 值 |
---|---|
Namespace | WebMatrix.WebData |
Assembly | WebMatrix.WebData.dll |
