WebSecurity IsAuthenticated 属性

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 对象
相关文章