ClientFormsAuthenticationMembershipProvider.Logout メソッド

定義

ユーザーをログアウトします。

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 をクリアし、 プロパティWindowsPrincipalstaticThread.CurrentPrincipal現在WindowsIdentityの を含む オブジェクトにリセットします。

このメソッドを呼び出すと、現在のユーザーはクライアント アプリケーション サービスに対して認証されなくなります。 つまり、 クラスを介してロールを取得したり、 クラスを ClientRoleProvider 介して設定を ClientSettingsProvider 取得したりすることはできません。 ただし、ユーザーは有効な Windows ID を持っている可能性があるため、次のようなコードから値をtrue受け取ることがあります。 Thread.CurrentPrincipal.Identity.IsAuthenticated ユーザーがクライアント アプリケーション サービスに対して認証されているかどうかを確認するには、 プロパティをIdentity介してstaticCurrentPrincipal取得された のIPrincipalプロパティ値がClientFormsIdentity参照であることを確認します。 次に、 プロパティを確認します ClientFormsIdentity.IsAuthenticated

現在のユーザーを再認証するには、 メソッドまたは メソッドをClientFormsAuthenticationMembershipProvider.ValidateUserstaticMembership.ValidateUser呼び出します。

適用対象

こちらもご覧ください