Thursday, June 14, 2007

Profile in asp.net 2.0 + Problem with Session + Differences between Session and Profile objects + Advantage of Profile Object

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 to maintaining his preferences, shopping cart etc.,
Session Object - 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.

Differences between Session and Profile objects
The major difference between Profile and Session objects are1. 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.

Profile Object
Examining the Profile objectA 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.

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

No comments:

Most Recent Post

Subscribe Blog via Email

Enter your email address:



Disclaimers:We have tried hard to provide accurate information, as a user, you agree that you bear sole responsibility for your own decisions to use any programs, documents, source code, tips, articles or any other information provided on this Blog.
Page copy protected against web site content infringement by Copyscape