10.1. Using Profiles

Problem

You want to make use of user profile data throughout your application without having to implement the infrastructure yourself.

Solution

Use the ASP.NET 2.0 membership and profile features by implementing the membership features described in Recipe 9.5, modify web.config to enable user profiles, define in web.config the specific user data to include in the profile, provide the ability to update the user profile data, and use the data as required in your application.

Modify web.config as follows:

  1. Add a <profile> element with a <provider> element defining the provider used to store and retrieve user-specific data.

  2. Add a <properties> element and an <add> element for each user-specific data item to be included in the profile.

In the .aspx file for the page used to enter the user-specific data:

  1. Add a server control for each user-specific data item.

  2. Add an Update button (or equivalent) to initiate the updating of the user-specific data.

In the code-behind class for the page used to enter user-specific data, use the .NET language of your choice to:

  1. Initialize the controls in the .aspx file with the current data from the user’s profile.

  2. Implement an event handler for the Update button click event and update the user’s profile from the data entered by the user.

The solution we have implemented to demonstrate the solution is shown in Examples 10-1, 10-2, 10-3 through 10-4. Example 10-1 shows the modifications made to web.config. Example 10-2 shows the .aspx file used to enter ...

Get ASP.NET 2.0 Cookbook, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.