Summary: ASP.NET provides a variety of different ways to maintain data between user requests. You can use Application objects, cookie, hidden fields, sessions, or cache objects, as well as a lot of methods. Decide when to use them sometimes difficult. This article will introduce the above techniques and give some guidance when using them. Although some of these technologies have existed in traditional ASPs, when there is a .NET framework assembly, when they use them to change. In order to maintain data in ASP.NET, you need to adjust the knowledge learned from the previous ASP.
With the arrival of the Web era, the management status in the state of incorrect HTTP is a big problem for web developers. There are recent different technologies that store and retrieve data. This article I will explain how the ASP.NET developer can maintain or transfer status through the page request.
In ASP.NET, there are several ways to maintain data between users - actually too much, so that no experience is very confused to use which object in which particular environment is very confused. In order to answer this question, we need to consider the following three conditions:
Who needs data?
How long is the data need to be maintained?
How big is the data set?
By answering these questions, you can decide which object provides the best solution to keep the ASP.NET application request interval. Figure 1 lists different status management objects and describes when using them. ASP.NET adds four new objects: cache, context, viewstate, and web.config files. ASP.NET also supports traditional ASP objects, including Application, cookie, Form Post, QueryString, and Sessions with hidden fields. Note that the correct usage of these five data containers has changed, so experienced programmers may need to learn some knowledge when considering these familiar objects.
Keeping Method Who wants to maintain how long the amount of data size Application All users The entire application life Date can be very short, and if the user does not delete it, you can very small, simple data Form Post A user to the next request (You can repeatedly span multiple requests) Any size queryString one or a group of users to the next request (can be used across multiple requests) Small, simple data sessions, a user's user activity, maintained a period of time (general 20 minutes) ) Can be any size, but because the user has a separate sessions storage, all it should be minimal. Cache All users or some users can be large as needed, simple and complicated Context A user can keep a large object, but it is generally not like this to use ViewState a web form minimum config file knows that the configuration file is updated. You can maintain a lot of data, usually tissue small strings and XML structures
Table 1. Data container objects in ASP.NET
Application
Let us explain the object by answering the status of the above status problem. Who needs data? All users need to access it. How long does it take to keep your data? Keep permanently or remain in the application survival. How big is the data? Can be any size - only a copy of the data at any given time exists.
In traditional ASP, the Application object provides a location that saves frequently used but few variables, such as menus content and reference data. Although Application in ASP.NET still exists as a data container, there are other objects of data in the Application collection of the traditional ASP application before.
In the traditional ASP, if the saved data is not changed at all in the application's life (or few changes, such as read-only data and most cases are read operations), Application objects are ideal. The connection string is the most common data sheet saved in the Application variable, but similar configuration data in ASP.NET is best saved in the web.config file. If you use the Application object, a question that needs to be considered is any write operation either in the Application_OnStart event (Global.asax) or in the Application.lock section. Although using Application.lock to ensure that the write operation is implemented correctly, it serves serving a request for Application objects, and this is a serious performance bottleneck for the application. Figure 2 demonstrates how to use Application objects, which includes a web form and its code file. Application.aspx