ASP.NET 2.0 : Tired with Sessions? - Use the new Profile property to store user information.

All of us who write web application enforce some mechanism by which we store a user's information for the period he is accessing the application. This may be from simply storing the User's ID to say a Welcome <username> to maintaining his preferences, shopping cart etc.,

So far, the Session object has been pretty useful to accomplish this task. With Whidbey (ASP.NET 2.0), there is a new feature Profile which allows us to store per-user settings to be used throughout the application. Settings can also be stored in an anonymous profile while users are not logged in, and then migrated to a logged-in user profile at a later time.

The major difference between Profile and Session objects are

1. Profile object is persistent whereas Session object is non-persistant.

2. Profile object uses the provider model to store information whereas Session object uses the In Proc, Out Of Process or SQL Server Mode to store information.

3. Profile object is strongly typed whereas Session object is not strongly typed.

The similarity between them is that Each user will automatically have a profile of his own similar to Sessions where each user will have his own Session State.

A user's profile is a collection of properties that define information you want to store for your web site's users. The user's profile is defined using a simple XML syntax in a configuration file (machine.config and/or web.config). Within your page, you reference a user's profile information with the Profile property. ASP.NET reads the schema defined in configuration, and automatically generates a class that is accessible from the Profile property on a page. You access properties on the Profile just as you would access properties on any other class.

Although the most common use of the Profile feature is storing data for authenticated users, the Profile feature also supports storing information for anonymous users. Storing profile information for anonymous users depends on the Anonymous Identification feature. The Profile and Anonymous Identification features work together to enable the use of the Profile property for anonymous users. The samples included in the QuickStart demonstrate using the Profile feature with both authenticated and unauthenticated users.

Prior to the start of the page lifecycle, ASP.NET ensures that the Profile is available for use by the page. Similarly, at the end of the ASP.NET page lifecycle, ASP.NET automatically saves the Profile to the underlying data store(s). As with other features such as Membership and Role Manager, the Profile feature has been designed with a provider-based model. Providers abstract the physical data storage for a feature from the classes and business logic exposed by a feature. The Profile feature ships with a provider for Microsoft™ SQL Server. You can create your own custom providers and configure them to work either the Profile feature. Pages that use the Profile feature will continue to work unchanged with your custom providers.

In addition to the Profile property, the Profile feature provides support for administration of profiles (both for authenticated users and anonymous users) with the ProfileManager. Common tasks that you perform with the ProfileManager include:

Searching for statistical information about all profiles, profiles for authenticated users, and profiles for anonymous users

Determine the number of profiles that have not been modified in a given period of time

Deleting individual profiles as well as deleting multiple profiles based on a profile's last modification date

We will examine the ways of Defining / Managing and Deleting Profiles in the Next Article(s).

Cheers and Happy Programming !!!

Print | posted on Thursday, July 7, 2005 1:54 PM

Comments on this post

# re: ASP.NET 2.0 : Tired with Sessions? - Use the new Profile property to store user information.

Requesting Gravatar...
very good!
Left by celio on Feb 21, 2009 8:32 PM

# re: ASP.NET 2.0 : Tired with Sessions? - Use the new Profile property to store user information.

Requesting Gravatar...
When switch to https the profile property ll continue on https or not?
Left by Boomi Nathan on Mar 02, 2010 12:24 AM

# re: ASP.NET 2.0 : Tired with Sessions? - Use the new Profile property to store user information.

Requesting Gravatar...
DOĞAL VE ŞİFALI BİTKİ İLACI
Left by meksika biberi zayıflama hapı on May 31, 2010 11:13 PM

Your comment:

 (will show your gravatar)