In this section we talk about the state management Application, Session and Cookie.
The variables created by the Application can be accessed anywhere within the system. Usually the website access statistics will be used more. To use it, we have to First create a global.asa file in the system (not WIN system). In fact, Session also uses this file.
Application is a shared object. It is created when the program starts running and continues until the program is closed. Variables are shared and can be used by everyone operating the program. Then there is trouble. If two people give him the command to modify the variable at the same time, who should he listen to? So, here we use the pessimistic Lock, every time a variable is operated, use Lock to lock it, and unlock UnLock when the operation is completed.
Next, we use it to create an access statistics
. The Session is different. This is established when everyone enters the program. Session object, that is to say, there is only one Application, and there are as many Sessions as there are people who use them. Sessions are not shared. When the person exits the program, the object will be destroyed after the system default of 20 minutes, of course. We can think of changing this time. If the person accesses the program again within the specified time, he will directly use the previously created Session object. But if he comes back after a specific time, he will have to re-create it.
We have to pay attention here
., Session in asp, php and other languages depends on Cookie. If the user does not accept Cookie, then Session cannot be used. However, .net has abandoned this approach. We only need to set the Cookieless attribute to True in the web.config file. He can start his own business without relying on anyone.
Let's talk about Cookie below. It is actually an object created on the hard disk or browser memory. We say that the Session object is stored on the server side, and the Cookie is stored on the client side. They are all designed to save some information about the customer. Session can only save the customer's status for a short time, because after all, we have to consider the load of the server, while Cookie can be saved for a long time, such as the Remember Me or Forum that we often see. It is often said to save for one day, one month, one year, etc.
We can go back to the example question from the previous lesson and take a look.