dd

WebSecurity - Logout()


定义

Logout() 方法注销当前用户。

C# 和 VB 语法

Logout()

实例

实例 C#

// 退出登录
WebSecurity.Logout();

// 跳转回主页
Response.Redirect("~/");

实例 VB

' 退出登录
WebSecurity.Logout()

' 跳转回主页
Response.Redirect("~/")

参数

无。

返回值

无。

错误和异常

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

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

备注

当用户已登录,ASP.NET 在 cookie 中设置一个身份验证令牌,让 ASP.NET 知道用户已登录的后续请求。

Logout() 方法移除身份验证令牌,注销用户。

技术数据

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