Logo

Navigation
  • Home
  • Services
    • ERP Solutions
    • Implementation Solutions
    • Support and Maintenance Solutions
    • Custom Solutions
    • Upgrade Solutions
    • Training and Mentoring
    • Web Solutions
    • Production Support
    • Architecture Designing
    • Independent Validation and Testing Services
    • Infrastructure Management
  • Expertise
    • Microsoft Development Expertise
    • Mobile Development
    • SQL Server Database and BI
    • SAP BI, SAP Hana, SAP BO
    • Oracle and BI
    • Oracle RAC
  • Technical Training
    • Learn Data Management
      • Business Intelligence
      • Data Mining
      • Data Modeling
      • Data Warehousing
      • Disaster Recovery
    • Learn Concepts
      • Application Development
      • Client Server
      • Cloud Computing Tutorials
      • Cluster Computing
      • CRM Tutorial
      • EDI Tutorials
      • ERP Tutorials
      • NLP
      • OOPS
      • Concepts
      • SOA Tutorial
      • Supply Chain
      • Technology Trends
      • UML
      • Virtualization
      • Web 2.0
    • Learn Java
      • JavaScript Tutorial
      • JSP Tutorials
      • J2EE
    • Learn Microsoft
      • MSAS
      • ASP.NET
      • ASP.NET 2.0
      • C Sharp
      • MS Project Training
      • Silverlight
      • SQL Server 2005
      • VB.NET 2005
    • Learn Networking
      • Networking
      • Wireless
    • Learn Oracle
      • Oracle 10g
      • PL/SQL
      • Oracle 11g Tutorials
      • Oracle 9i
      • Oracle Apps
    • Learn Programming
      • Ajax Tutorial
      • C Language
      • C++ Tutorials
      • CSS Tutorial
      • CSS3 Tutorial
      • JavaScript Tutorial
      • jQuery Tutorial
      • MainFrame
      • PHP Tutorial
      • VBScript Tutorial
      • XML Tutorial
    • Learn Software Testing
      • Software Testing Types
      • SQA
      • Testing
  • Career Training
    • Career Improvement
      • Career Articles
      • Certification Articles
      • Conflict Management
      • Core Skills
      • Decision Making
      • Entrepreneurship
      • Goal Setting
      • Life Skills
      • Performance Development
      • Personal Excellence
      • Personality Development
      • Problem Solving
      • Relationship Management
      • Self Confidence
      • Self Supervision
      • Social Networking
      • Strategic Planning
      • Time Management
    • Education Help
      • Career Tracks
      • Essay Writing
      • Internship Tips
      • Online Education
      • Scholarships
      • Student Loans
    • Managerial Skills
      • Business Communication
      • Business Networking
      • Facilitator Skills
      • Managing Change
      • Marketing Management
      • Meeting Management
      • Process Management
      • Project Management
      • Project Management Life Cycle
      • Project Management Process
      • Project Risk Management
      • Relationship Management
      • Task Management
      • Team Building
      • Virtual Team Management
    • Essential Life Skills
      • Anger Management
      • Anxiety Management
      • Attitude Development
      • Coaching and Mentoring
      • Emotional Intelligence
      • Stress Management
      • Positive Thinking
    • Communication Skills
      • Conversation Skills
      • Cross Culture Competence
      • English Vocabulary
      • Listening Skills
      • Public Speaking Skills
      • Questioning Skills
    • Soft Skills
      • Assertive Skills
      • Influence Skills
      • Leadership Skills
      • Memory Skills
      • People Skills
      • Presentation Skills
    • Finding a Job
      • Etiquette Tips
      • Group Discussions
      • HR Interviews
      • Interview Notes
      • Job Search Tips
      • Resume Tips
      • Sample Resumes
 

ASP.NET Personalization: User Profiles and Themes

By Exforsys | on August 23, 2005 |
ASP.NET 2.0

ASP.NET Personalization: User Profiles and Themes

In this tutorial you will learn about Personalization – User Profiles and Themes, Inbuilt providers in ASP.NET 2.0 and also Create and execute a Shopping cart application with Personalization features.

Surfers would love to see on the website the content which is customized to their needs. ASP.NET offers a personalization feature which enables users to do just that. Personalization is a storage system that manages all the data related to users of the application. It integrates seamlessly with SQL server or Microsoft Access or any other database that developer’s wishes to use. A little code enables the creation of modular pages where personalization can manage the session’s services and the user can return to the screen at a later time to find the controls in the position he had left them. He can add controls from the catalog or remove a control and store it in the catalog for later use. This is called the persistent storage of structured data using a friendly and type safe API.

In ASP.NET personalization is implemented as user profiles and themes. These are complementary to each other. The model of personalized data is defined by the application and it is parsed at runtime by compiling that model into a class. The data in the personalized class corresponds to information specific to the current user. The internal working of the software is masked from both the user and the developer but the loading and saving of personalized data is completely transparent to the user.

Personalization:

In ASP.NET 2.0 Personalization is activated by default and is available to all authenticated users. However, before actually using personalization it is important to specify the data that needs to the be saved for each user. The profile of the user has to be defined in the < personalization > section of the web.config file. Individual properties may be placed and the profile properties can be defined by using the < property > tags.

< ?xml version= “1.0”
< configuration >
………….
< system.web >
………….
< profile >
< properties >
………….< add name="Nickname" / >
< / properties >
< / profile >
………….
< / system.web >
< / configuration
>

In the source code file now the IntelliSense kicks in and you can call this.Profile. and the property is displayed in the drop down box. This is because a corresponding typed class is generated the moment the profile was defined. It was then compiled and integrated into the website’s assembly.

The current profile can be caught either by using the object model of the current page or through the HttpContext class. The personal data store is returned through the ‘Profile’ property.

Personalization is based on the provider model. Two providers are inbuilt into the ASP.NET 2.0—one for Microsoft Access and another for SQL Server. By default the profile is stored in the Microsoft Access database aspnetdb.mdb. The profile information is stored in direct relationship to the membership data. The GetProfile() method enables access to other profiles in the database. The user name has to be passed as a parameter to the method and the HttpPersonalization instance is returned with the data stored in the profile.

HttpPersonalization profile=this.Profile.GetProfile(“xxx”);
String name= Profile.Nickname;

It is possible to write into the data and the same can be saved if it is done explicitly by calling the CommitSettings() method to commit the data to the data source.

All properties of the profile are saved as strings by default. However other objects can be placed in the profile if they are serializable. DateTime, for instance can be stored by specifying a class name of the desired data type via the attribute type while defining the profile properties. It will read as

< Property name=”birthdate” type=”System.DateTime” / >

In the above example the complete class name of the data type including the corresponding namespace such as System.DateTime has been specified. However if a static value has to be used, it can be added with the attribute defaultValue.

The profile created can now be edited using a new page editprofile.aspx by each user in a type safe manner. We can see how this is done a little later in this tutorial.

Complex data types can also be stored in the profile from the base class library. The only precondition is that these data types should be serializable. To define the type the class’s full name and its namespace have to be specified. Though all values are serialized as string by default, property values are stored next to each other and the values are distinguished by their start and end positions.

PropertyNames: Username: X:0:1: Theme:X:7:22:
PropertyValuesString:XXX

However, string serialization is not considered advisable for reference types. The XML or binary format is more acceptable. The desired string can be assigned with the desired setting to the SerializeAs attribute. For instance a StringCollection can be serialized in the database as XML and will be available through the property name “xxx” that is serialized. Look at the example below to understand the concept better.

< personalization >
< profile >
< add name=”MyName” / >
< add name= “Birthdate” type= “System.DateTime” / >
< add name = “mycollections”
type= “System.Collections.Specialized.StringCollection” serializeAs=”Xml” / >
< / profile >
< / personalization >

This new profile property of the page and the HttpContext classes can now store ‘mycollections’. The URL of the current page can be dropped into the collection through a LinkButton located on the master page. The code for this button would look like this:

Void LinkButton_Click(object sender, System.EventArgs e)
{
HttpPersonalization profile = (HttpPersonalization) this.Context.Profile;
Profile.mycollections.Add(this.Request.Url.ToString());

It must be noted in this context that the master page does not allow type safe access to custom profiles. The HttpContext class is used to redeliver the profile through the HttpPersonalizationBaseClass and give access to the custom properties. Individual data also can be stored in a profile. The condition, again being serialization. We will see how this is done when we come to the practical half of the tutorial.

Anonymous users are supported in ASP.NET 2.0. This feature will have to be activated and custom properties of such users can be saved even if they are anonymous. How is this done? The profile property features have to be activated in the Web.config file. Enter the following code in the Web.config file

< configuration >
< system.Web >
< anonymousIdentification enabled= “ture” / >
< / system.web >
< / configuration
>

Each property in the profile can be defined using the allowAnonymous attribute. If this property is not set, the properties will not be stored. We will see how the anonymous user’s profiles are stored when we look at the shopping cart example a little later in this tutorial.

Anonymous user profiles can be migrated to Authenticated user profiles by using the MigrateAnonymous event of the class PersonalizationModule. This is done in the global.asax file which is usually added to the website to fulfill this function.

Using the personalization features of ASP.NET 2.0 it is easy to store custom information belonging to the individual users. Simple strings or complex data structures can be added. Anonymous users can be identified during their visit to the site and later pinpointed if they repeat their visit.

.

.

Creating a Shopping cart application with Personalization features:

A shopping cart application has to have two classes—Cart and Product. The Cart derives from System.Collections.Generic.List class and Product is a business object prototype with some attributes. Both classes must be marked as Serializable.

1. Create a Website project and add an Application_code directory to the Web site.

2. Right click on this directory and select “Add New Item…” and select class.

3. Name the class file Cart.cs and click Add.

4. Note that a new class file has been created for your project.

5. Enter the following code in the Cart.class file.

Click here to view sample code

6. Now create another class file called Product.cs and enter the following code in it.

Click here to view sample code

7. Now create a web.config file and enter the following code.

< personalization >
< profile >
< add name="Cart" type="Cart" SerializeAs="Xml" / >
< / profile >
< / personalization
>

8. An objectDataSource control will now have to be used to access the basket. Open a .aspx file and enter the following code to use the shopping cart. The page will contain a GridViewControl and a DetailsView control. The former will help users show, edit and delete the contents of the cart and the latter will help adding of new items.

Click here to view sample code

9. The design view of the Shopping cart application would look as under:

10. Now create a CartManager class and type in the following code

Click here to view sample code

11. Save all and click F5 to execute.

In this section of the tutorial we have seen how to use personalization to store the profile of the user and also to save the features personalized by users. Complex features and data structures can also be stored by users with personalization as we have seen in the shopping cart application above. In the next section we shall look at Themes and skins which are closely associated with personalization and is often used with it.

« « ASP.NET Web Pages and Layout
ASP.NET Data Access features » »

Author Description

Avatar

Editorial Team at Exforsys is a team of IT Consulting and Training team led by Chandra Vennapoosa.

Free Training

RSSSubscribe 392 Followers
  • Popular
  • Recent
  • What’s New in the .NET Framework 2.0 ?

    July 26, 2005 - 0 Comment
  • ASP.NET Managing Membership and Roles

    August 6, 2005 - 0 Comment
  • ASP.NET Page Object Model

    August 14, 2005 - 0 Comment
  • ASP.NET Displaying Master-Detail Data on the Same Page

    September 13, 2005 - 0 Comment
  • ASP.NET Working with Web Parts

    August 22, 2005 - 0 Comment
  • ASP.NET Configuring Page-Level Caching

    August 30, 2005 - 0 Comment
  • ASP.NET Server Controls

    August 15, 2005 - 0 Comment
  • Displaying Master-Detail Data on Separate Pages in ASP.NET

    September 16, 2005 - 0 Comment
  • ASP.NET Using Web Parts and Controls in Web Pages

    August 22, 2005 - 0 Comment
  • ASP.NET Setting Application-Level Caching

    August 30, 2005 - 0 Comment
  • Application Development in .NET

    November 21, 2007 - 0 Comment
  • ASP.NET Advanced Site Functionality

    September 16, 2005 - 0 Comment
  • ASP.NET : Dynamic Image control

    September 16, 2005 - 0 Comment
  • ASP.NET Creating Web Wizards

    September 16, 2005 - 0 Comment
  • Displaying Master-Detail Data on Separate Pages in ASP.NET

    September 16, 2005 - 0 Comment
  • ASP.NET Displaying Master-Detail Data on the Same Page

    September 13, 2005 - 0 Comment
  • ASP.NET DataBound Controls – Details View

    September 13, 2005 - 0 Comment
  • ASP.NET Using a Grid to Display Detail Information

    September 13, 2005 - 0 Comment
  • ASP.NET Adding Sorting and Paging in GridView

    September 10, 2005 - 0 Comment
  • ASP.NET GridView Filtering

    September 10, 2005 - 0 Comment

Exforsys e-Newsletter

ebook
 

Related Articles

  • Application Development in .NET
  • ASP.NET Advanced Site Functionality
  • ASP.NET : Dynamic Image control
  • ASP.NET Creating Web Wizards
  • Displaying Master-Detail Data on Separate Pages in ASP.NET

Latest Articles

  • Project Management Techniques
  • Product Development Best Practices
  • Importance of Quality Data Management
  • How to Maximize Quality Assurance
  • Utilizing Effective Quality Assurance Strategies
  • Sitemap
  • Privacy Policy
  • DMCA
  • Trademark Information
  • Contact Us
© 2023. All Rights Reserved.IT Training and Consulting
This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish.AcceptReject Read More
Privacy & Cookies Policy

Privacy Overview

This website uses cookies to improve your experience while you navigate through the website. Out of these, the cookies that are categorized as necessary are stored on your browser as they are essential for the working of basic functionalities of the website. We also use third-party cookies that help us analyze and understand how you use this website. These cookies will be stored in your browser only with your consent. You also have the option to opt-out of these cookies. But opting out of some of these cookies may affect your browsing experience.
Necessary
Always Enabled
Necessary cookies are absolutely essential for the website to function properly. This category only includes cookies that ensures basic functionalities and security features of the website. These cookies do not store any personal information.
Non-necessary
Any cookies that may not be particularly necessary for the website to function and is used specifically to collect user personal data via analytics, ads, other embedded contents are termed as non-necessary cookies. It is mandatory to procure user consent prior to running these cookies on your website.
SAVE & ACCEPT