自强学堂
自强学堂:学习、分享、让你更强!
Razor 实例HTMLCSSJAVASCRIPTJQUERYSQLPHPBOOTSTRAPANGULARXML
 

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

技术数据

名称
NamespaceWebMatrix.WebData
AssemblyWebMatrix.WebData.dll


WebSecurity 对象 WebSecurity 对象