In Asp.net, session storage is not as simple as ASP, and three storage methods are provided in total. due to the fault of a Web software used by more than 2000 people recently, it is difficult for a user to log on to the server at a certain time every morning. If the session value is lost, Only IIS or machine is restarted. then
Program Back to normal. The same problem will not occur all day, but the next day is still! This phenomenon lasted for several days. I checked the log files. The number of visitors per second during the peak hours was about 20, and about 100 online users. In the future, the number of visitors will increase, in order to solve this strange problem, we started with the software and applied the three methods.
Open the Web. config file
<Sessionstate
Mode = "inproc"
Stateconnectionstring = "TCPIP = 127.0.0.1: 42424"
Sqlconnectionstring = "Data Source = 127.0.0.1; trusted_connection = yes"
Cookieless = "false"
Timeout = "20"
/>
The default mode is inproc. This mode is the same as the previous ASP mode, that is, the server stores session information in the IIS process. When IIS is disabled or restarted, the process information will be lost, but this mode has the highest performance (not tested, read the book). This mode is ASP.. net.
Due to this pattern, my failure caused the inetinfo.exe process to crash due to a large volume of memory. If the user cannot log on to the server and the session value is lost, I used another session storage method to store the session information outside the process.
First, open the management tool to find the service, find the service named ASP. NET State service, start it, and change it to automatic start. At this time, you can see a process named aspnet_state.exe in the task manager. This is the process of saving session information.
Then, return to the Web. config file and change the mode Value to StateServer to save the file. OK.
mode = "StateServer"
stateconnectionstring = "TCPIP = 127.0.0.1: 42424"
sqlconnectionstring = "Data Source = 192.10.78.76; user ID = sa; Password = sa "
cookieless =" false "
timeout =" 20 "
/>
when we restart IIS In this mode, the saved session value will not be lost. In addition, you can save the information in other machine processes, but you also need to change stateconnectionstring = "TCPIP = 127.0.0.1: 42424" and change the IP address to another machine.
other measures are also taken. for example, the database is separated from the Web server, the database server does not provide Web Services, and the Web server does not provide database services.
then, the connection pool is expanded due to ASP.. net. NET data access the default number of connection pools is 100, and then I expanded to 6000 by adding the statement
"Server = (local); database = RGS; Password = sa; user ID = sa; Max pool size = 6000; min pool size = 5; pooling = true "
change memorylimit in processmodel in machine. config to 95. The default value is 60, indicating that the IIS process automatically restarts after the memory usage exceeds 60%. Then, we will write other methods to optimize IIS and increase the IIS cache of the Registry.
after completing these optimization steps, the whole software runs well. No blockage was found on the next day, but the third day appeared again, the last method I used was to store the session in sqlserver. I think the stability should be better.
to use sqlserver, run installsqlstate on the SQL server computer in the session state. SQL or installpersistsqlstate. SQL (default location: systemroot \ Microsoft. net \ framework \ versionnumber) Both scripts create a database named aspstate. The difference between the two scripts lies in the location of the aspstatetempapplication and aspstagetempsessions tables. Installsqlstate. the SQL script adds these tables to the tempdb database, which will lose data when the computer restarts, while installpersistsqlstate. the SQL script adds these tables to the aspstate database. session data is retained when the database is restarted.
then in the application's web. in the config file, set the mode attribute of the element to sqlserver, and set the sqlconnectionstring attribute to integrated security = sspi; Data Source = servername;
<Sessionstate mode = "sqlserver"
Sqlconnectionstring = "Integrated Security = sspi; Data Source = dataserver ;"
Cookieless = "false"
Timeout = "20"/>
</Sessionstate>
If deployed on another machine, you can change it to, with the username and password added.
<Sessionstate
Mode = "sqlserver"
Stateconnectionstring = "TCPIP = 127.0.0.1: 42424"
Sqlconnectionstring = "Data Source = 192.10.78.76; user id = sa; Password = sa"
Cookieless = "false"
Timeout = "20"
/>
This deployment is complete. If you do not want to use this method, you can delete it as long as the corresponding directory (systemroot \ Microsoft. net \ framework \ versionnumber) Find uninstallpersistsqlstate. SQL or uninstallsqlstate. run the SQL file.
Note that, whether StateServer or sqlserver mode is used, when session is used to convert objects, note that objects must be serialized first, that is, serializable must be added before the class; otherwise, an error will occur!
This article Excerpted from http://www.cnblogs.com/mingfei200169/articles/mingfei200.html