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,並將 屬性WindowsPrincipal重設為static
Thread.CurrentPrincipal包含目前WindowsIdentity的物件。
呼叫這個方法之後,目前的使用者就不會再針對用戶端應用程式服務進行驗證。 這表示您無法透過 ClientRoleProvider 類別擷取角色,也無法透過 類別擷 ClientSettingsProvider 取設定。 不過,因為使用者可能有有效的 Windows 身分識別,所以您可能仍會收到 true
來自程式碼的值,例如: Thread.CurrentPrincipal.Identity.IsAuthenticated
。 若要判斷是否要為用戶端應用程式服務驗證使用者,請確認Identity透過 屬性擷取的static
CurrentPrincipalIPrincipal屬性值是ClientFormsIdentity參考。 然後,檢查 ClientFormsIdentity.IsAuthenticated 屬性。
若要重新驗證目前的使用者,請呼叫 ClientFormsAuthenticationMembershipProvider.ValidateUser 方法或 static
Membership.ValidateUser 方法。
適用於
另請參閱
意見反應
https://aka.ms/ContentUserFeedback。
即將登場:在 2024 年,我們將逐步淘汰 GitHub 問題作為內容的意見反應機制,並將它取代為新的意見反應系統。 如需詳細資訊,請參閱:提交並檢視相關的意見反應