ASP. NET provides session objects, allowing programmers to identify, store, and process the context information of several requests from the same browser object to a specific network application on the server. Session corresponds to the same conversation between the browser and the server. When the browser first requests a page of the network application, the server triggers the session_onstart event; the session_onend event is triggered when the dialog times out or is disabled. Programmers canCodeTo process tasks related to the same conversation, such as opening and releasing resources to be used by the conversation. In ASP. to use the session object in the net program, make sure that the enablesessionstate attribute in the @ page command of the page is true or readonly, and in the web. the sessionstate attribute is correctly set in the config file. Session status persistence in ASP. NET is determined by the mode attribute marked by the <system. Web> label in the web. config file. This attribute has four possible values: Off, inproc, StateServer, and sqlserver. If it is set to off, the session will be disabled. Inproc is the default setting. This mode is similar to the previous ASP session state method, and the session state is saved in ASP. net process, its advantages are obvious: performance. Data access within a process is naturally faster than that of a process. However, the session state of this method depends on the ASP. NET process. When the IIS process crashes or is restarted normally, the State stored in the process will be lost. To overcome the disadvantages of inproc mode, ASP. NET provides two methods to maintain the session status outside the process. ASP. net first provides a Windows Service: aspstate. After the service is started, Asp.. NET applications can set the mode attribute to "sateserver" to use the status management method provided by the Windows service. In addition to setting the mode attribute to StateServer in the web. config file, you must also set the IP address and port number of the StateServer server. IfInIISRunning on the machineStateServerThe IP address is 127.0.0.1, and the port number is usually 42424. The configuration is as follows: Mode = "StateServer" STATEC In this mode, session state storage does not depend on the failure or restart of the IIS process, and the session state is stored in the memory space of the StateServer process. Another session Status mode is sqlserver mode. This mode saves the session Status in the SQL Server database. Before using this mode, you must have at least one SQL Server server and create the required tables and stored procedures in the server .. . Net SDK provides two scripts to simplify this work: installsqlstate. SQL and uninstallsqlstate. SQL. Files in these two countries are stored in the following path: <% Systemdriver %> \ winnt \ Microsoft. NET \ framework \ <% version %> \ To configure the SQL Server server, you can run the SQL server command line tool osql.exe in the command line. Osql-s [server name]-U [user]-P [Password] <installsqlstate. SQL For example: Osql-s (local)-u As-P ""-I installsqlstate. SQL After necessary database preparation, change the mode attribute of the sessionstate element in the web. config file to "sqlserver" and specify the SQL connection string. The details are as follows: Mode = "sqlserver" Sqlc In sqlserver mode, the session state is independent from the IIS server, and the SQL server cluster can be used to make the status storage independent from a single SQL Server, in this way, the application can be highly reliable. |