Anonymous Personalization

It is common to allow your users to personalize your site before identifying themselves. A classic example of this is Amazon.com, which lets you add books to your shopping cart before you log in (you only need to log in when you are ready to purchase what is in your cart).

ASP.NET 2.0 supports the ability to link anonymous personalized data with a specific user’s personalized data, once that user logs in (you don’t want to lose what’s in your cart when you do log in).

Begin by creating a new web site named AnonymousPersonalization. Delete Default.aspx and copy the SitePersonalization web site to your new site, and test that it is working as expected.

Next, to enable anonymous personalization , you must update your web.config file, adding the following in the <system.web> section:

            
    <anonymousIdentification enabled="true" />

Also, add the attribute-value pair allowAnonymous="true"to the CHOSENBOOKS element of web.config.

Redesign your Welcome.aspx page so the hyperlink that links to the profile information page, and the lbBooks list box, are both outside of the LoginView control (so you can see the hyperlink and the list, even if you are not logged in). While you are at it, rename Add Profile Info to Profile Info, since you will be using this link to add, and edit, the profile info, as shown in Example 13-3.

Example 13-3. Modified Welcome.aspx

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Welcome.aspx.cs" Inherits="Welcome_aspx" %> <!DOCTYPE html PUBLIC ...

Get Programming ASP.NET, 3rd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.