An Extended Look at the Profile Object - Part 2
page 1 of 4
Published: 24 Oct 2005
Unedited - Community Contributed
Abstract
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 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.
by Bilal Haidar
Feedback
Average Rating: 
Views (Total / Last 10 Days): 27225/ 36

Introduction

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

<configuration>
<system.web>
<authentication mode="forms" />
<anonymousIdentification enabled="true" />
<profile enabled="true">
<properties>
<add name="FirstName" defaultValue="Bilal" type="string" 
allowAnonymous="true" />
<add name="LastName" defaultValue="Haidar" type="string" allowAnonymous="true" />
</properties>
</profile>
</system.web>
</configuration>

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.


View Entire Article

User Comments

Title: Property IsDirty when inheriting ProfileBase (2nd option)   
Name: AiM
Date: 2006-07-20 11:33:35 AM
Comment:
I tried both versions, when I set the configuration in the config file it works ok, but when I implement the class that inherits from ProfileBase the changes aren't saved. I overrided the Save method just to check for the value of the IsDirty property, and it is false.
How this should work, are there other details for the inherited option I don't know?
Title: Re:   
Name: Bilal Haidar [MVP]
Date: 2005-12-01 5:21:55 AM
Comment:
Hello:
You should wait for Part3 of this series to know everything about the database and etc...

Regards
Title: Where is Database ?   
Name: Zeeshan Ali
Date: 2005-12-01 5:17:02 AM
Comment:
You didn't specify the database to which the profile will persist. Where the Peofile data is being persist ?? Cookies ? or What ?
Title: Win app   
Name: Anders H
Date: 2005-11-30 4:44:45 PM
Comment:
If you want to use this example, in a web app,you add data and work with it in a webb app, then you want to get this data in a windows service app for example mailing things based on the items in this profile data, then you need to get to this data from a win app, how do you do that???
Title: Re:   
Name: Bilal Haidar [MVP]
Date: 2005-11-30 1:29:12 AM
Comment:
Well, the Profile object has its own HttpModule events. The way it works is as follows:
At runtime, the configuration section of the profile object in the Web.config will be tranformed into a strongly typed object which is then added to the HttpContext.
At the beginning of the request, the profile data are loaded from database, then at the end of the request, if the data is dirty (has been changed) it will be saved back. Saving data at every request is a matter of a Flag you can configure.
Hope that answers you well.

Regards
Title: One of the more useful articles I've seen in a long time!   
Name: Colin
Date: 2005-11-29 6:12:03 PM
Comment:
I just learned how to create a custom Role- and Membership- Provider and I saw no mention of this class anywhere! I wish I'd known because I spent a long time digging for something like this, and ended up coming up with a custom implementation using an HttpModule and Session.

Have you discovered in your study of the class what the default persistance mechanism is the profile? Is it stored in the user's context or persisited, like forms authentication info, in a secured cookie or something?
Title: Re:   
Name: Bilal Haidar [MVP]
Date: 2005-11-29 1:51:35 AM
Comment:
Hi to all:
Profile object can be thought of as advanced session object. In windows applications, no need for that concept, so it is ot available there.
Thanks for the comments.

Regards
Title: good article   
Name: DotNETKans
Date: 2005-11-29 12:21:16 AM
Comment:
hi Bilal,

Good article mate. Keep it up.
Title: From a win32 app   
Name: Anders H
Date: 2005-11-28 12:39:01 PM
Comment:
How can i access this from an win32 application, it complain on profile object others than ordinary type eg. string, int etc....??

Product Spotlight
Product Spotlight 





Community Advice: ASP | SQL | XML | Regular Expressions | Windows


©Copyright 1998-2024 ASPAlliance.com  |  Page Processed at 2024-04-16 7:29:47 AM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search