Session state loss and resolution strategies in the ASPNET application

Source: Internet
Author: User

Session is easy to lose, solution

1.

Learn about the next Web Park

An application pool is the default to open a worker process, but can also open multiple worker processes, which can improve performance, this feature is called the Web garden, is a small "Web farm", you do not need to use multiple computers to transfer the same content (Web farm), Instead, you can use multiple processes on a single computer to deliver the same content.
To configure the Web garden:

iis-> application pool, right-click Using application Pool, properties--performance->web max number of working processes

Set the maximum number of processes greater than 1, if this value is greater than 1, each request will start a new worker process instance, the maximum number of processes that can be started and the number of processes you have set, up to 4000000. Subsequent requests are sent to the worker process in a circular manner. But there are two points to consider when using the Web Park:

    1. Each work process consumes system resources and CPU utilization, and too many work processes will not only lead to a sharp depletion of system resources and CPU usage, but also cause resource competition;
    2. Each worker process has its own state data, because the request is routed to the application pool worker process in a circular way, which results in inconsistent data, such as session loss;

Some friends also found that there are multiple w3wp processes, very do not understand, some friends even think is a virus. In fact, this is completely related to the Web garden settings, a working process is a w3wp.

2.

Asp. NET provides 5 session-state options:

InProc

StateServer

Sql server

Custom

Off

1. InProc

The INPROC option supports saving session state within a process, in effect saving session state in a w3wp.exe worker process. This means that the save session state data is saved separately on each server, so that other servers cannot access the current server session state data. This also means that an application pool recycle operation will result in the loss of session state. This solution runs the fastest without considering the off option, but this solution will not work properly in a Web farm environment unless we apply a sticky session mechanism. If the sticky session mechanism is used and the Web garden is not used, then INPROC is a viable solution.

If you need to set session state in the Web. config file or other configuration file, you can add a sessionstate tag in the configuration file's <system.web> configuration section, as shown in the following code.

<configuration>

<system.web>

<sessionstate mode= "InProc"/>

</system.web>

</configuration>

2. StateServer

StateServer is another solution offered by Microsoft, but this workaround does not provide failover functionality. When ASP. NET is successfully installed on the server, Windows Services adds a service named ASP. NET State Service, which is disabled by default, but can be enabled at any time. We need to set the startup mode of the service to automatic so that the service will start automatically each time the system restarts.

Setup steps: Run->services.msc->asp.net status service (enabled, and set automatic) (Find service, sort by name)

By default, the ASP. NET sessionstate service cannot be accessed remotely, and if you need to run the ASP. SessionState service remotely, you will need to hkey_local_machine\system\ in the registry The value of Currentcontrolset\services\aspnet_state\parameters\allowremoteconnection is set to 1.

<sessionstate mode= "StateServer"/>

If you do not intend to use the default state server in the local server, you can set the parameters as needed. <sessionstate mode= "StateServer" stateconnectionstring= "

tcpip=10.0.0.10:42424 "/>

Local servers can sometimes appear:

HTTP Error 500.0-internal Server error calling LoadLibraryEx failed on ISAPI filter "C:\PHP\php5isapi.dll"

At this point, read-only access to anonymous users is added to the folder

3. SQL Server

Microsoft provides a third solution that is SQL Server session state. This solution is a very appropriate solution if a SQL Server cluster is used in the current application runtime environment. SQL Server session state has the highest performance overhead compared to other scenarios, but the performance impact of this scenario is negligible because SQL Server session state provides redundancy support. Before you deploy this solution, it is important to ensure that the system performance meets the requirements of the current application, while also ensuring that the system is well-scalable.

SQL Server session state configuration is complex and requires the use of the Aspnet_regsql.exe tool

4. Custom

Asp. NET supports the implementation of custom session state providers. Therefore, a solution that differs from Microsoft solutions can be implemented. Similar to other options, once a custom solution has been successfully developed and deployed to the server, we must update the Web. config file for the site and the Web. config file under the application root to point to the custom provider.

5. Off

The session state can be closed completely, and in some cases it makes sense to do so, because when session state is enabled, system performance degrades even if we do not use session state. To turn off session state, we can follow the "InProc" section, the only difference being to choose off instead of selecting in Process. In IIS Manager, this practice is known as not enabled.

Third-party session-State Solutions

Scaleout Software (www.scaleoutsoftware.com) and Alachisoft (www.alachisoft.com) are two well-known third-party software vendors dedicated to providing Web farm session state solutions. The products of these two third-party software vendors can be applied to highly available, highly scalable Web farm systems, and can save session state data in-process while supporting immediate replication of all modifications, and the product also supports saving session data out of process, in order to save session data outside the process, You need to use a custom worker process that runs on all servers.

Session state loss and resolution strategies in the ASPNET application

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.