Personalization and Themes
In Chapter 6 we discussed the new infrastructure feature of Membership. Membership is used to store user credentials and offers APIs for validating those credentials as well as managing users. A common question that often comes up when discussing Membership is how additional user details are stored; for example, your application may want to associate first and last names with the user or store a theme.
While Membership does store some user information, such as when the user last logged on, the logon username, and so on, it is not specifically designed to store additional user characteristics such as first and last names. Storing additional user data is the responsibility of the new Personalization feature.
Personalization is a persistent user storage system for storing any data related to the user of your application. Several good examples that we'll use to demonstrate Personalization in this chapter include the following:
Common user characteristics such as first and last names
User application properties such as a shopping cart
Application-specific data, such as the personalization settings used by the ASP.NET Forums (http://www.asp.net/forums)
UI properties, such as the look and feel of controls
The Personalization services feature of ASP.NET 2.0 was designed with several specific goals in mind. Understanding these goals will help you successfully use Personalization in your application.
Strongly typed access:
Unlike features such as Cache, Session, or Application, which require a key to retrieve a value from a dictionary, Personalization uses strongly typed properties, meaning that properties are easier to discover and use. For example, you may replace Session code with Personalization for storing the user's first name, as shown below:
Dim firstName As String
' First name retrieved from Session
firstName = Session("FirstName")
' First name retrieved from Profile
firstname = Profile.FirstName
Unlike Session state, which looks up the values of Session on each request regardless of whether or not the data is used, Personalization retrieves data only when it is requested:
Extensible data store:
Personalization implements the new provider model design pattern. This design pattern exists to allow you to abstract the Data Access Layer away from the Personalization APIs. For example, if you have data stored in an AS/400, you could use Personalization to access that data by authoring a provider to communicate to the AS/400. Later in this chapter we're going to look at a provider for the ASP.NET Forums to demonstrate how easy it is to author a provider. Providers can be configured as the default or set at runtime.
Below are the topics we're going to explore in this chapter:
Storing and retrieving user personalization data
The provider model design pattern
Authoring a customer Personalization provider
Customizing the look of a site through themes
As we'll see, Personalization is a very powerful new feature of ASP.NET 2.0. It has been designed to integrate seamlessly with the new Membership services feature—but it can work independently as well.