Asp. Application of Session storage mode in net

Source: Internet
Author: User
Tags config iis log sql net sessions
In ASP.net, the session storage mode is not as single as the ASP, a total of three storage methods, due to a recent 2000-person use of the Web software has failed, users every morning at a certain moment of difficulty landing, and then the session lost value appears, only restart IIS, or machine. Then the program is back to normal.

The same problem will not happen all day, but the next day is still! This phenomenon lasted for several days, I checked the log file, the peak of the number of visitors per second about 20 people, and about 100 people online, the number of visitors will increase later, in order to solve this strange problem, first from the software, So three ways have been applied.

Open 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 the InProc type, which is the same as the previous ASP mode, where the server stores session information in the IIS process, and the process information is lost when IIS shuts down and resets, but the performance of this mode is the highest (specifically not measured, read on), This pattern is the default method for asp.net.

Due to the failure of this mode, my consideration was that the Inetinfo.exe process crashed due to the excessive amount of traffic. The user is difficult to log in so that the session loses a fault, I used another way of storing sessions to store the sessions information outside the process.

First, open the Admin tool to find the service, find the service named: ASP.net State Service, start it. and change it to auto start. At this point you can see a process named Aspnet_state.exe in Task Manager. This is where we save the session information.

Then, go back to the Web.config file to change the value of mode to StateServer and save the file. Ok.

< sessionstate

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"

/>

This mode when we restart IIS, the saved session value is not lost. In addition, this method can save the information in the process of other machines, but also change the stateconnectionstring= "tcpip=127.0.0.1:42424", the IP address to other machines.

Other measures have been taken. such as separating the database from the Web server, the database server does not provide a Web service, and the Web server does not provide a database service.

Then expand the connection pool, because the number of Ado.net data access default connection pool in asp.net is 100, then I expand to 6000 by the way to add

"Server= (local);

Database=rgs;

Password=sa;

User Id=sa;

Max Pool Size = 6000;

Min Pool Size = 5;

Pooling=true "


Finally, the memorylimit in the processmodel in Machine.config is changed to 95, the default is 60, which means that the IIS process will automatically restart after the memory occupies more than 60%. Then write some other ways to optimize IIS, increase the IIS cache for the registry, and so on.

When I finished these optimization steps, the whole software running better, the next day did not find the phenomenon of congestion, but the third day, the situation again, there is no way, I took the last one. The session storage method in ASP.net is to store the session in SQL Server, and I think the stability should be stronger.

To use SQL Server, first run InstallSqlState.sql or installpersistsqlstate.sql on the computer of the session state SQL Server (default location: systemroot\ Microsoft.net\framework\versionnumber below) Two scripts create a database called ASPState, The difference between two scripts is the placement of aspstatetempapplication and aspstagetempsessions tables. The InstallSqlState.sql script adds these tables to the tempdb database, which loses data when the computer is reset, and the InstallPersistSqlState.sql script adds the tables to the ASPState database. Retains session data when the database restarts.

Then, in the application's Web.config file, set the < sessionstate> element's mode property to SQL Server, and finally set the sqlConnectionString property to integrated security =sspi;data Source=servername;

< sessionstate mode= "SQL Server" sqlconnectionstring= "Integrated Security=sspi;

Data source=dataserver; "

Cookieless= "false"

Timeout= "/>"

</sessionstate>


If deployed on other machines you can change to, plus user name and password


< sessionstate

mode= "SQL Server"

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 can be deleted, just in the appropriate directory (Systemroot\microsoft.net\framework\versionnumber) Find UninstallPersistSqlState.sql or UninstallSqlState.sql files to run. This describes the session storage mode in asp.net.

Finally note that, regardless of the use of StateServer or SQL Server mode, when using the session to convert objects, note that the object to be serialized first, is in the class before adding serializable, otherwise there will be errors!



Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.