Chapter 6. Maintaining State
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. Why do you need to maintain state in the first place? The reason is that it can 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 web-based application, such as keeping track of items in a shopping cart or noting viewing preferences. You can also significantly enhance the performance of heavily used applications by making commonly used data available to any user, without making repeated trips to a database.
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 often improve application performance. Recipe 6.1 shows how to retrieve data from a database and place it in the
Applicationobject, thereby making it accessible to all users of an application. This is known as maintaining state at the application level.- Session state
Experienced web users expect you to remember who they are for the duration of their sessions at your site. Preserving this ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access