O'Reilly logo

ASP.NET 2.0 Cookbook, 2nd Edition by Geoffrey T. LeBlond, Michael A Kittel

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

10.2. Inheriting a Profile

Problem

You want to use ASP.NET 2.0’s profile features but you do not want to define the profile information in the web.config file because you use the same profile definition in multiple applications.

Solution

Implement the membership features to provide user authentication, as described in Recipe 9.5, create a custom class that inherits from ProfileBase, add properties for each user-specific data item you want to include in the profile, and modify the <profile> element in web.config to set the inherits attribute to the custom class you created to store the user’s profile data.

Use the .NET language of your choice to create a custom class for the profile data:

  1. Inherit from ProfileBase.

  2. Add a property for each data item to be included in the user profile

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. Set the inherits attribute of the <profile> element to the fully qualified namespace of the custom class you created.

Example 10-5 shows the modifications made to web.config for this solution. The custom user profile class is shown in Examples 10-6 (VB) and 10-7 (C#). The example page that uses the user profile information is identical to the example in Recipe 10.1 and is shown in Examples 10-2, 10-3 through 10-4.

Discussion

If you use the same user profile data in multiple applications, defining the profile in web.config creates a maintenance problem when any changes ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required