In previous projects, sessions were often prone to loss and depressing. After searching online, there was still a solution.
By default, the session settings in the web. config file are as follows:
<Sessionstate mode = 'inc' stateconnectionstring = 'tcpip = 127.0.0.1: 42424 'sqlconnectionstring = 'data source = 127.0.0.1;
Trusted_connection = Yes 'cookieless = 'true' timeout = '60'/>
The sessionstate label has an attribute mode, which can be inproc, StateServer, or sqlserver (case sensitive ).
The process is unstable,
When some events occur (such as anti-virus software), the process restarts, resulting in the loss of sessions stored in the process.
Solution: Use the StateServer mode instead of the inproc mode, and set "ASP. NET Status Service" in the service to auto-Enable. In this way,
The session does not depend on a process.
<Sessionstate mode = "StateServer" cookieless = "false" timeout = "20000"/>
Session loss is a common problem. After I know how to solve this problem, I will share it with you.
There are two solutions to the session loss problem:
1) Save the session in an sate server.
2) Save the session in SQL Server. This method is rarely used, so the first method is selected.
First, modify the session section of the webconfig file based on the information found on the Internet. As follows:
<Sessionstate mode = "StateServer" cookieless = "false" timeout = "240" statectatenetworktimeout = "14400"/>
Start the Asp.net state Server Service on the computer 10.164.222.122.
Basically. Try it out.
After three hours, the session is still available. Even more importantly, my computer is restarted and the session is still available on the web pages opened on other computers. After some experience, I feel really good.
. NET Framework general reference
<Sessionstate> element
Configure session Status settings for the current application.
<Configuration>
<System. Web>
<Sessionstate>
<Sessionstate mode = "off | inproc | StateServer | sqlserver"
Cookieless = "True | false"
Timeout = "number of minutes"
STATEC
Sqlc
Statenetworktimeout = "number of seconds"/>
Required attribute
Attribute options
Mode specifies where the session status is stored.
Off indicates that the session status is not enabled.
Inproc indicates the local storage session status.
StateServer indicates storing session status on a remote computer.
Sqlserver indicates that sessions are stored on SQL Server.
Optional attributes
Attribute options
Cookieless specifies whether a session without a cookie is used to identify a client session.
True indicates that a session with no cookie is used.
False indicates that no cookie-free sessions should be used. The default value is false.
Timeout specifies the number of minutes before a session is abandoned. The default value is 20.
Stateconnectionstring specifies the name and port of the server that stores the session Status remotely. For example, "TCPIP = 127.0.0.1: 42424 ". This attribute is required when mode is StateServer.
Sqlconnectionstring specifies the connection string for SQL Server. Apsara stack ASP technology. For example, "Data Source = localhost; Integrated Security = sspi; initial catalog = northwind ". This attribute is required when mode is sqlserver.
When statenetworktimeout uses StateServer mode to store the session status, it specifies the idle time (in seconds) for the TCP/IP network connection between the Web server and the status server before the session is abandoned ). The default value is 10.
Remarks
Use StateServer mode
Make sure that the server running ASP. NET Status Service is the remote server that stores session status information. This service is installed with ASP. NET. Its default location is <drive >:\ systemroot \ Microsoft. NET \ framework \ version \ aspnet_state.exe.
In the Web. config file of the application, set mode = StateServer and set the stateconnectionstring attribute. For example, STATEC.
Use sqlserver Mode
Run installsqlstate. SQL on the computer running SQL Server (which stores the session State) (the default installation location is <drive >:\ systemroot \ Microsoft. NET \ framework \ version ). This creates a database named aspstate, which has a new stored procedure and has the aspstatetempapplications table and aspstatetempsessions table in the tempdb database.
In the Web. config file of the application, set mode = sqlserver and set the sqlconnectionstring attribute. For example, sqlc. Feifei! ASP Technology Park
Example
The following example specifies several session Status configuration settings.
<Configuration>
<System. Web>
<Sessionstate mode = "inproc"
Cookieless = "true"
Timeout = "20"/>
</Sessionstate>
</System. Web>
</Configuration>
Requirements
Included in: <system. Web>
Web platforms: IIS 5.0, IIS 5.1, and IIS 6.0
Configuration File: machine. config, Web. config
Configuration section handler: system. Web. sessionstate. sessionstatesectionhandler
See
ASP. NET Configuration | ASP. NET configuration architecture | sessionstatemodule
IIS6 in Windows2003 server is added to the application pool to recycle useless process functions, when the application pool automatically recycles the process due to a website program error or too many accesses to prevent the website from entering the "dead" status, at this time, the collection of the application pool will cause the session variable to be cleared, and the session variable will disappear.
To solve this problem in Windows2003, we started the ASP. Net state service on the server and made some changes in the system's machine. config. By default, the session state mode is StateServer. If the root directory of your website is configured with a web. in the config configuration file, change mode = "inproc" to mode = "StateServer". The following code prevents the loss of session variables:
<Sessionstate
Mode = "StateServer"
STATEC
Sqlc
Cookieless = "false"
Timeout = "30"
/>
+ Note: Only applicable to users that support Asp.net.