16.4. Summary

In this chapter you learned how to use the Profile feature that ships with ASP.NET 3.5 to store user related data. You can use Profile to keep track of data for authenticated but also for anonymous users.

Setting up a profile is a pretty straightforward operation. You need to create a <profile> element in the web.config file with a <properties> child element and then add one or more properties using <add /> elements. To group related properties you use the <group> element.

When you set up the profile, you access its properties through the Profile property of the Page class. This always accesses the profile for the current user. Any changes you make to this profile are persisted for you automatically at the end of the ASP.NET life cycle.

By design, Profile properties are only accessible to logged-in users. However, you can easily change this by turning on anonymous identification.

To access the Profile of a user other than the one associated with the current request, you can use the GetProfile method. Any changes made to this profile are not persisted automatically, so you must call Save to send the changes to the database.

Now that your pages contain more and more code, chances are that bugs and problems will creep into your application. In the following chapter you learn how to use exception handling to avoid those problems from ending up in the user interface. You also learn how to debug your code, so you can fix problems before they occur.

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.