ClientFormsAuthenticationMembershipProvider.Logout 方法
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
注销用户。
public:
void Logout();
public void Logout ();
member this.Logout : unit -> unit
Public Sub Logout ()
例外
IsOffline 属性值为 false
,并且成员资格提供程序无法访问身份验证服务。
示例
以下示例代码演示如何使用此方法注销用户。
private void logoutButton_Click(object sender, EventArgs e)
{
SaveSettings();
ClientFormsAuthenticationMembershipProvider authProvider =
(ClientFormsAuthenticationMembershipProvider)
System.Web.Security.Membership.Provider;
try
{
authProvider.Logout();
}
catch (WebException)
{
MessageBox.Show("Unable to access the authentication service." +
Environment.NewLine + "Logging off locally only.",
"Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
ConnectivityStatus.IsOffline = true;
authProvider.Logout();
ConnectivityStatus.IsOffline = false;
}
Application.Restart();
}
Private Sub logoutButton_Click(ByVal sender As Object, _
ByVal e As EventArgs) Handles logoutButton.Click
SaveSettings()
Dim authProvider As ClientFormsAuthenticationMembershipProvider = _
CType(System.Web.Security.Membership.Provider, _
ClientFormsAuthenticationMembershipProvider)
Try
authProvider.Logout()
Catch ex As WebException
MessageBox.Show("Unable to access the authentication service." & _
Environment.NewLine & "Logging off locally only.", _
"Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning)
ConnectivityStatus.IsOffline = True
authProvider.Logout()
ConnectivityStatus.IsOffline = False
End Try
Application.Restart()
End Sub
注解
方法 Logout 从 Cookie 缓存中清除所有身份验证 Cookie,并将 属性重置 static
Thread.CurrentPrincipal 为 WindowsPrincipal 包含当前 WindowsIdentity的 对象。
调用此方法后,当前用户不再对客户端应用程序服务进行身份验证。 这意味着无法通过 类检索角色, ClientRoleProvider 而无法通过 ClientSettingsProvider 类检索设置。 但是,由于用户可能具有有效的 Windows 标识,因此你仍可能从如下所示的代码中收到 true
值: Thread.CurrentPrincipal.Identity.IsAuthenticated
。 若要确定是否为客户端应用程序服务对用户进行身份验证,请确认Identity通过CurrentPrincipalstatic
属性检索的 的IPrincipal属性值是引用ClientFormsIdentity。 然后,检查 ClientFormsIdentity.IsAuthenticated 属性。
若要重新对当前用户进行身份验证,请 ClientFormsAuthenticationMembershipProvider.ValidateUser 调用 方法或 static
Membership.ValidateUser 方法。
适用于
另请参阅
反馈
https://aka.ms/ContentUserFeedback。
即将发布:在整个 2024 年,我们将逐步淘汰作为内容反馈机制的“GitHub 问题”,并将其取代为新的反馈系统。 有关详细信息,请参阅:提交和查看相关反馈