16.2. Other Ways of Dealing with Profile

In the final section of this chapter you see two other useful ways of dealing with the Profile feature in ASP.NET. First, you see how to use the Profile for anonymous users followed by a discussion on accessing the profile of a user other than the current user.

16.2.1. Anonymous Identification

The Profile feature is extremely easy to configure, yet very powerful. All you need to do to give logged-in users access to their profiles is create a few elements in web.config and the ASP.NET run time takes care of the rest. But what about anonymous users? What if you wanted to store data for your visitors who haven't signed up for an account or aren't logged in yet? For those users you need to enable anonymous identification. With anonymous identification, ASP.NET creates an anonymous user in the aspnet_Users table for every new visitor to your site. This user then gets a cookie that is linked to the anonymous user account in the database. On every visit, the browser sends the cookie with the request, enabling ASP.NET to associate a user, and thus a Profile, with the user for the current request.

To enable an anonymous profile, you need to do two things: turn on anonymous identification, and modify some or all profile properties to expose them to anonymous users.

Enabling anonymous identification is easy with the following element in web.config, directly under <system.web>:

<anonymousIdentification enabled="true" cookieName="PlanetWroxAnonymous" ...

Get Beginning ASP.NET 3.5: In C# and VB 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.