10.3. Using and Migrating Anonymous Profiles


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


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.


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 ...

Get ASP.NET 2.0 Cookbook, 2nd Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.