Session:
The current browser user expires after the browser is closed or after a specified time (20 minutes by default ).
At the same time, according to the session storage method, there are different situations:
- Inproc: In this mode, the session will be saved in the IIS process. If the IIS process is restarted, the session will be lost.
- StateServer: Session will be stored in ASP. in the net state service process, the restart of the IIS process will not cause session failure, only ASP.. Net state service process will not expire after being restarted. When session is stored in this mode, the ASP. Net state service process can be in a different PC than IIS.
- SQL Server: Use sqlserver to save sessions. This is the safest solution. Session values are stored in the database using data information.
When you use StateServer and sqlserver to save the session, because the object is not transmitted in a process, this object must be serializable ([serializable]).
Viewstate:
Valid on current client and current page
Storing too much data will seriously affect the page reading efficiency
COOKIE:
Valid on the current machine. You can specify the expiration time.
Static variable:
Stored on the server, shared by all users
Static variables are stored in the corresponding class on the page. If the object on the page is recycled, static variables are also recycled.