HTTP is a stateless protocol, so the status cannot be shared among different requests. However, it is useful to maintain the status between different requests. For example, the implementation of shopping cart on a shopping website depends on this state.
ApplicationProgramStatus Management
Presumably many peopleCodeSegment is very familiar:
Application. Lock (); application ["myglobalcounter"] = (INT) application ["myglobalcounter"] + 1; application. Unlock ();
Application is an instance of the httpapplicationstate class.
It exists throughout the lifecycle of a Web application.
Session Status
When a browser requests an application for the first time, the server starts a session,
Future requests will share these session statuses.
The first response of these requests will return a sessionid,
In the future, this sessionid will be used as the token to access the session status.
Sessionid can be transmitted in two ways:
1) Cookie
2) No cookie is used, but is inserted into the URL and delivered to the server.
ASP. NET supports three session Status modes: inproc, StateServer, and sqlserver.
| |
Advantages |
Disadvantages |
| Inproc |
1st segment is directly read from aspnet_wp.exe, so the performance is the best.
|
1)aspnet_wp.exe may be recycled for many reasons (for example, the web. config, bin directory or memory usage in the virtual directory has reached the maximum. Therefore, it is quite unstable.
2) It is not applicable to Web garden deployment, but not to Web farm deployment. |
| StateServer |
1) Session variables in this mode are stored in a Windows service independent of IIS, so they are not affected by the collection mechanism of IIS worker processes.
2) It is applicable to the Web garden and web farm deployment modes. |
1) there is a problem of Cross-process or cross-machine (because this Windows service can be deployed on another server), and the performance is low. |
| Sqlserver |
In addition to StateServer (1) and 2), StateServer has the following advantages:
3) more persistent |
1) lower performance, because you need to read SQL Server, reverse sequence, and so on. |
reference: http://msdn.microsoft.com/en-us/library/87069683 (vs.71). aspx