AuthenticationService.Logout Method (Action(Of LogoutOperation), Object)
WCF RIA Services
[WCF RIA Services Version 1 Service Pack 2 is compatible with either .NET framework 4 or .NET Framework 4.5, and with either Silverlight 4 or Silverlight 5.]
Asynchronously logs out an authenticated user from the server with the specified callback method and user state.
Namespace: System.ServiceModel.DomainServices.Client.ApplicationServices
Assembly: System.ServiceModel.DomainServices.Client (in System.ServiceModel.DomainServices.Client.dll)
'Declaration Public Function Logout ( _ completeAction As Action(Of LogoutOperation), _ userState As Object _ ) As LogoutOperation 'Usage Dim instance As AuthenticationService Dim completeAction As Action(Of LogoutOperation) Dim userState As Object Dim returnValue As LogoutOperation returnValue = instance.Logout(completeAction, _ userState)
Parameters
- completeAction
- Type: System.Action(Of LogoutOperation)
An action that will be invoked immediately after the operation completes and is called in all cases, including success, cancellation, and error. This parameter is optional.
- userState
- Type: System.Object
The state that will be set into UserState. This parameter is optional.
Return Value
Type: System.ServiceModel.DomainServices.Client.ApplicationServices.LogoutOperationThe result of the operation.
| Exception | Condition |
|---|---|
| InvalidOperationException | This method is called while another asynchronous operation is still being processed. |
If this method returns normally, a LoggedOut event may be raised. Also, successful completion of this operation will update the User. To handle an operation error, MarkErrorAsHandled can be called from the operation completion callback or from a Completed event handler.
The following example shows a call to the Logout method with a callback method.
Protected Overrides Sub OnNavigatedTo(ByVal e As System.Windows.Navigation.NavigationEventArgs) SetControlVisibility(WebContext.Current.User.IsAuthenticated) End Sub Private Sub LoginButton_Click(ByVal sender As Object, ByVal e As RoutedEventArgs) Dim lp As LoginParameters = New LoginParameters(UserName.Text, Password.Password) WebContext.Current.Authentication.Login(lp, AddressOf Me.LoginOperation_Completed, Nothing) LoginButton.IsEnabled = False LoginResult.Text = "" End Sub Private Sub LoginOperation_Completed(ByVal lo As LoginOperation) If (lo.HasError) Then LoginResult.Text = lo.Error.Message LoginResult.Visibility = System.Windows.Visibility.Visible lo.MarkErrorAsHandled() ElseIf (lo.LoginSuccess = False) Then LoginResult.Text = "Login failed. Please check user name and password." LoginResult.Visibility = System.Windows.Visibility.Visible ElseIf (lo.LoginSuccess = True) Then SetControlVisibility(True) End If LoginButton.IsEnabled = True End Sub Private Sub SetControlVisibility(ByVal isAuthenticated As Boolean) If (isAuthenticated) Then LoginBorder.Visibility = System.Windows.Visibility.Collapsed WelcomeText.Text = "Welcome " + WebContext.Current.User.Name WelcomeText.Visibility = System.Windows.Visibility.Visible LogoutButton.Visibility = System.Windows.Visibility.Visible Else LoginBorder.Visibility = System.Windows.Visibility.Visible WelcomeText.Visibility = System.Windows.Visibility.Collapsed LogoutButton.Visibility = System.Windows.Visibility.Collapsed End If End Sub Private Sub LogoutButton_Click(ByVal sender As Object, ByVal e As RoutedEventArgs) WebContext.Current.Authentication.Logout(AddressOf Me.LogoutOperation_Completed, Nothing) End Sub Private Sub LogoutOperation_Completed(ByVal lo As LogoutOperation) If (Not (lo.HasError)) Then SetControlVisibility(False) Else Dim ew As ErrorWindow = New ErrorWindow("Logout failed.", "Please try logging out again.") ew.Show() lo.MarkErrorAsHandled() End If End Sub
Show: