Udostępnij za pośrednictwem


How to: Work Offline with Client Application Services

You can use client application services in offline mode when the ASP.NET AJAX application services that your application connects to are unavailable. This enables you to authenticate users, retrieve user roles, and retrieve or save user Web settings by using a local data cache. In offline mode, all service requests automatically go to the local cache without requiring changes to your code.

The offline status is stored on the local hard disk at the location indicated by the Application.UserAppDataPath property. This means that the offline status is stored on a per-user, per-application basis. When your application is in offline mode, all calls that would normally go to the remote service will access the local data cache instead. By default, offline values are stored on the local file system. Alternatively, you can configure your application to use a SQL Server or SQL Server Compact Edition version 3.5 database. For more information, see How to: Configure Client Application Services.

The following procedure describes how put your application into offline mode when your application is configured to use client application services. For guidance on end-to-end testing of client application services features, see Walkthrough: Using Client Application Services.

To put your application in offline mode

  1. Ensure that your application is properly configured to use client application services in offline mode, as described in How to: Configure Client Application Services. You will typically select the Save password hash locally to enable offline login option, enabling you to authenticate users while the application is offline. You might also want to set the Roles service cache timeout value to a large value to prevent the role information from expiring in offline mode.

  2. Set the static ConnectivityStatus.IsOffline property to true. The following code example demonstrates setting this property in a CheckBox.CheckedChanged event handler so that the user can enter or exit offline mode.

    Private Sub checkBox1_CheckedChanged( _
        ByVal sender As Object, ByVal e As EventArgs) _
        Handles checkBox1.CheckedChanged
    
        ConnectivityStatus.IsOffline = checkBox1.Checked
    
    End Sub
    
    private void checkBox1_CheckedChanged(object sender, EventArgs e)
    {
        ConnectivityStatus.IsOffline = checkBox1.Checked;
    }
    

Robust Programming

The example code in this topic demonstrates the simplest usage of offline mode in a Windows client application. You might want to add more code that executes when your application returns to online mode. For example, you can silently revalidate the user to make sure that remote service calls will not fail because of an expired authentication cookie. Additionally, you can update the local Web settings cache and the remote Web settings service with any changes that were made while offline. For example code that demonstrates these behaviors, see Walkthrough: Using Client Application Services.

See Also

Tasks

How to: Configure Client Application Services

Walkthrough: Using Client Application Services

Concepts

Client Application Services Overview

Reference

ConnectivityStatus.IsOffline

Other Resources

Client Application Services