O'Reilly logo

ASP.NET 2.0 Cookbook, 2nd Edition by Geoffrey T. LeBlond, Michael A Kittel

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

10.3. Using and Migrating Anonymous Profiles

Problem

You want to store profile information for users who are not logged into your application.

Solution

Implement the solution described in Recipe 10.1, add an <anonymousIdentification> element to the web.config file to enable anonymous identification, and set the allow-Anonymous attributes of the profile property elements to true in web.config for each of the profile properties that should be stored for anonymous users.

Modify web.config as follows:

  1. Add an <anonymousIdentification> element to enable the anonymous identification features and to define the cookie used to identify the user.

  2. Set the allowAnonymous attribute of each profile property that is to be persisted for anonymous users to true.

Example 10-8 shows the modifications made to web.config for this solution. The example page that uses the user profile information is identical to the example in Recipe 10.1 and is shown in Examples 10-2, 10-3 through 10-4.

Discussion

Storing anonymous user profile data was possible in ASP.NET 1.x, but, since there was no inherent support in 1.x, you had to implement it yourself. As part of the profile features, ASP.NET 2.0 provides full support for storing data for anonymous users. Like storing profile data for authenticated users, it can be configured with little code.

When anonymous identification is enabled, ASP.NET 2.0 generates a GUID to use as the identity for all visitors to your application on their first visit. This GUID is stored in a cookie ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required