This article is the second article in the series of articles on the new personalization feature of ASP.NET 2.0, the Profile object. The Profile object allows the web application to store data for each visitor to the application, save that data to a storage medium like Microsoft SQL Server, and then retrieve the data when the same visitor returns to the application.
The first article looked at the basics of the Profile object, and showed how it can use simple and grouped properties configured in the application's configuration file (web.config). But the Profile object is not limited to using simple and grouped properties. This article will examine two ways of using custom objects with the Profile object.
In the previous article, we explained the basics of the Profile object and provided an example on how to use simple and grouped properties as part of the Profile object. The following configuration section shows how we can use simple properties with the Profile object.
Listing 1: Simple Profile Property Configuration
<authentication mode="forms" />
<anonymousIdentification enabled="true" />
<add name="FirstName" defaultValue="Bilal" type="string"
<add name="LastName" defaultValue="Haidar" type="string" allowAnonymous="true" />
In the above listing, we define two simple properties, FirstName and LastName, both of type string and each with a default value.
As you can see, it is an easy matter to add simple properties to the Profile object. However, in more advanced applications, we need to use our own custom objects with the Profile object. We do not want to decompose our custom object so that it can be represented by a group of simple properties; we want to be able to store our custom object in the Profile object. How is this done? That is one of the topics of this article.