Monday, January 23, 2012

Profile Properties

ASP.NET provides a feature called profile properties, which allows you to store user-specific data. It is similar to session state, except that unlike session state, the profile data is not lost when a user's session expires. The profile properties feature uses an ASP.NET profile, which is stored in a persistent format and associated with an individual user. The ASP.NET profile allows you to easily manage user information without requiring you to create and maintain your own database. In addition, the profile makes the user information available using a strongly typed API that you can access from anywhere in your application. You can store objects of any type in the profile. The ASP.NET profile feature provides a generic storage system that allows you to define and maintain almost any kind of data while still making the data available in a type-safe manner.


Web.config file code
    <anonymousIdentification enabled="true"/>
        <add name ="count" allowAnonymous="true" defaultValue="0" type="int"/>

.cs file code
    protected void Page_Load(object sender, EventArgs e)
       int i= Profile.count;
       lbl_FindVisitorsCount.Text = Convert.ToString(i);

Advantages of Profile Properties:
1: Data persistence. Data placed in profile properties is preserved through IIS restarts and worker-process restarts without losing data because the data is stored in an external mechanism. Additionally, profile properties can be persisted across multiple processes, such as in a Web farm or a Web garden.

2: Platform scalability   Profile properties can be used in both multi-computer and multi-process configurations, therefore optimizing scalability scenarios.

3: Extensibility. In order to use profile properties, you must configure a profile provider. ASP.NET includes a SqlProfileProvider class that allows you to store profile data in a SQL database, but you can also create your own profile provider class that stores profile data in a custom format and to a custom storage mechanism, such as an XML file, or even to a Web service. For more information.

Disadvantages of Profile Properties:
1: Performance considerations. Profile properties are generally slower than using session state because instead of storing data in memory,the data is persisted to a data store.

2: Additional configuration requirements. Unlike session state, the profile properties feature requires a considerable amount of configuration to use. To use profile properties, you must not only configure a profile provider, but you must pre-configure all of the profile properties that 
you want to store. For more information, see ASP.NET Profile Properties Overview and Defining ASP.NET Profile Properties.

3: Data maintenance. Profile properties require a certain amount of maintenance. Because profile data is persisted to non-volatile storage, you must make sure that your application calls the appropriate cleanup mechanisms, which are provided by the profile provider, when data becomes stale.

No comments: