WebSecurity 属性 - IsAuthenticated


定义

IsAuthenticated 属性是一个布尔值,指示当前用户是否已通过身份验证(已登录)。

如果当前用户已通过身份验证,则该属性值是一个布尔值 true,否则是 false

C# 和 VB 语法

  1. WebSecurity.IsAuthenticated

实例

实例 C#

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

实例 VB

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

备注

IsAuthenticated 属性是只读的。它不能通过代码更改。

错误和异常

在下面的情况下,任何对 WebSecurity 对象的访问将抛出一个 InvalidOperationException

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

技术数据

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