Latest web development tutorials

WebSecurity HasUserId 屬性

WebSecurity 對象 WebSecurity對象

定義

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沒有初始化(或者在網站配置中禁用)

技術數據

名称
Namespace WebMatrix.WebData
Assembly WebMatrix.WebData.dll


WebSecurity 對象 WebSecurity對象