WebSecurity 屬性 - IsAuthenticated

定義
IsAuthenticated 屬性是一個布爾值,指示當前用戶是否已通過身份驗證(已登錄)。
如果當前用戶已通過身份驗證,則該屬性值是一個布爾值 true,否則是 false。
C# 和 VB 語法
WebSecurity.IsAuthenticated
實例
實例 C#
if (!WebSecurity.IsAuthenticated)
{
Response.Redirect("~/Account/Login");
}
{
Response.Redirect("~/Account/Login");
}
實例 VB
if !WebSecurity.IsAuthenticated then
Response.Redirect("~/Account/Login")
end if
Response.Redirect("~/Account/Login")
end if
備註
IsAuthenticated 屬性是只讀的。它不能通過代碼更改。
錯誤和異常
在下面的情況下,任何對 WebSecurity 對象的訪問將拋出一個 InvalidOperationException:
- InitializeDatabaseConnection() 方法沒有被調用
- SimpleMembership 沒有初始化(或者在網站配置中禁用)
技術數據
名稱 | 值 |
---|---|
Namespace | WebMatrix.WebData |
Assembly | WebMatrix.WebData.dll |
