Anonymous Personalization

Anonymous personalization refers to any personalization that is performed for users that are not already authenticated. By default Personalization is configured to not allow anonymous personalizationthis was done purposely for the following reasons.

  1. Anonymous personalization data can easily fill a database, and you need to have a strategy in place for managing this data.

  2. Personalization, by default, relies on the username value of the authenticated users to store/associate personalization data for a user .

To use anonymous personalization you must take two steps.

  1. Enable anonymous identification, which is disabled by default.

  2. Specify which Personalization properties can be set for anonymous users.

Specifying which Personalization properties can be used by anonymous users is done by adding the allowAnonymous element to your Personalization property. For example, Listing 7.9 shows how to allow anonymous users to use the Cart property.

Listing 7.9 Configuring Anonymous Personalization
 <configuration>   <system.web>     <anonymousIdentification enabled="true" />     <personalization>       <profile>         <property name="FirstName" />         <property name="LastName" />         <property name="Cart"                   allowAnonymous="true"                   type="Market.ShoppingCart, market"                   serializeAs="Binary" />       </profile>     </personalization>   </system.web> </configuration> 

Anonymous users browsing the site can now add items to the shopping cart without being required to first authenticatea behavior most sites want to support! Personalization data for the user is then automatically keyed off the value of the anonymous ID.

While anonymous personalization is desirable, at some point the user may either authenticate or create an account on the system. For example, in an e-commerce site you would want the user to create an account before checking out. Giving the user an account would allow you to capture more specific data about the user required for fulfilling their order, such as the shipping address.

As discussed earlier in the Anonymous Identification section, when an authenticated user signs in, the anonymous ID is removed. With anonymous personalization this would orphan any anonymous data. When switching from an anonymous user to an authenticated user, you will potentially need to migrate anonymous personalization data to the authenticated user's profile.

Migrating from Anonymous to Authenticated Users

The migration strategy from anonymous to authenticated is designed to allow the developer to make the decisions through code as to which data is migrated and which data is not migrated (as opposed to automatically migrating all data). This design allows you to make intelligent decisions. For example, if you have a shopping cart populated by an anonymous user who then authenticates, you may find that the authenticated user's profile also has items within the shopping cart. Ideally you would add the anonymous shopping cart items rather than replacing them.

Migration is accomplished through a special event raised by Personalization:

 Personalization_OnMigrateAnonymous 

This event is raised after the AnonymousIdentification_OnRemove event is raised. Any migration code needs to exist within the Personalization_OnMigrateAnonymous event. The event allows you to access the anonymous profile through the PersonalizationMigrateEventArgs.AnonymousId property, and by using this property you can retrieve the profile of the anonymous user as well as values (see Listing 7.10).

Listing 7.10 Migrating Anonymous Users
 <%@ Import Namespace="System.Security.Principal" %> <script runat="server">   Public Sub Personalization_OnMigrateAnonymous (sender As Object,                                 e As PersonalizationMigrateEventArgs)     ' Migrate the shopping Cart     Profile.Cart = Profile.GetProfile(e.AnonymousId).Cart     End Sub </script> 

The anonymous migration strategy provides you with the most flexibility since you make all the decisions about what data is migrated and what data is no longer needed.



A First Look at ASP. NET v. 2.0 2003
A First Look at ASP. NET v. 2.0 2003
ISBN: N/A
EAN: N/A
Year: 2004
Pages: 90

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net