Introduction

Because HTTP is an inherently stateless protocol, you must use special techniques when you want to preserve information about users as they move from one page to the next or when they leave and reenter your application. Saving this information is known as saving or maintaining state. You need to maintain state to improve the user’s experience with an ASP.NET application. By maintaining state, you can maintain the continuity between pages and between sessions that users demand of a webbased application, such as keeping track of items in a shopping cart or noting viewing preferences. You can enhance the performance of heavily used applications by making commonly used data available to any user, without making repeated trips to a database.

Be aware, however, that maintaining state can sometimes result in a decline in performance. For example, if you place large objects in session state you can negatively affect an application’s performance by tying up system resources.

You can preserve information at the application, session, and page levels of an ASP.NET application. The recipes in this chapter demonstrate how each is done:

Application state

By making commonly used data available to all users of an application, you can sometimes improve application performance. Recipe 7.1 shows how to retrieve data from a database, place it in the Application object, and make it accessible to all users of an application. This is known as maintaining state at the application level.

Session ...

Get ASP.NET 2.0 Cookbook, 2nd 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.