How to: Access User Settings with Client Application Services
You can use client application services to retrieve user application settings from an existing Microsoft Ajax profile service. The client application services Web settings feature integrates with the application settings feature provided in .NET Framework 2.0. For more information about application settings, see Application Settings Overview. For information about how to set up the Microsoft Ajax profile service, see Using Profile Information with Microsoft Ajax.
The following procedure describes how to access Web settings when your application is configured to use the Web settings service. For more information, see How to: Configure Client Application Services. This procedure requires access to a running Microsoft Ajax profile service. For guidance on end-to-end testing of client application services features, see Walkthrough: Using Client Application Services.
To access Web settings in your Windows client application
Ensure that your application is properly configured to use client application services, as described in How to: Configure Client Application Services. At a minimum, you must specify a Web settings service location on the Services page of the project designer. To retrieve Web settings configured for use by authenticated users, you must also specify an authentication service location or use Windows authentication.
On the Settings page of the project designer, click Load Web Settings.
A Login dialog box appears.
To retrieve settings configured on the server for use by all authenticated users, specify valid user credentials and click Log In. To retrieve settings configured for use by all anonymous users, click Skip Login.
The settings configured on the server appear in the designer. Additionally, a Settings class (accessed as Properties.Settings.Default in C# and My.Settings in Visual Basic) is generated or updated to include properties based on the settings. This class manages all interactions with the remote Web settings service through the ClientSettingsProvider class. Although you can access the ClientSettingsProvider class directly, you will typically access it indirectly through the Settings class, as shown in the next step. For more information, see Client Application Services Overview.
You cannot use the Settings page to modify the default Web settings values nor to access non-default values. Additionally, if the default values are modified on the server, you must retrieve the new default values by clicking the Load Web Settings button. The Synchronize button is not used by client application services.
In your application code, use properties of the generated class to get or set the Web settings values.
The following code example assumes that you have retrieved a setting named MySetting and that your application contains a Label named myLabel.
In your application code, use the ApplicationSettingsBase.Save method to save changed settings values back to the Web settings service.
The example code in this topic demonstrates the simplest usage of Web settings in a Windows client application. When you access or save Web settings through client application services, however, your code can throw a WebException. This indicates that the service is unavailable or that the user login has expired. For an example of how to handle a WebException in these cases, see Walkthrough: Using Client Application Services.