Latest web development tutorials

WebSecurity IsAuthenticated 屬性

WebSecurity 對象 WebSecurity對象

定義

IsAuthenticated屬性是一個布爾值,指示當前用戶是否已通過身份驗證(已登錄)。

如果當前用戶已通過身份驗證,則該屬性值是一個布爾值true ,否則是false


C# 和VB 語法

WebSecurity.IsAuthenticated


實例

實例C#

if (!WebSecurity.IsAuthenticated)
{
Response.Redirect("~/Account/Login");
}

實例VB

if !WebSecurity.IsAuthenticated then
Response.Redirect("~/Account/Login")
end if


備註

IsAuthenticated屬性是只讀的。 它不能通過代碼更改。


錯誤和異常

在下面的情況下,任何對WebSecurity對象的訪問將拋出一個InvalidOperationException

  • InitializeDatabaseConnection()方法沒有被調用
  • SimpleMembership沒有初始化(或者在網站配置中禁用)

技術數據

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


WebSecurity 對象 WebSecurity對象