Current location - Quotes Website - Collection of slogans - How iis Load Balancing Saves Session State
How iis Load Balancing Saves Session State
I. Inproc mode

Inproc is the default setting. This pattern is similar to the previous ASP session state method. The session state will be saved in the ASP.NET process, and its advantage is obvious: performance. Data access in the process will naturally be faster than boasting. However, the session state in this method depends on the ASP.NET process. When the IIS process crashes or restarts normally, the state saved in the process will be lost.

Second, StateServer mode.

In order to overcome the shortcomings of Inproc mode, ASP.NET provides two ways to maintain session state out of process.

ASP.NET first provided a Windows service: ASPState. After starting this service, ASP.NET applications can set the mode property to "SateServer" to use the state management method provided by this 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 server running StateServer. The specific configuration method is as follows:

2. 1 If StateServer is running on the machine where IIS is located, the IP address is 127.0.0. 1, and the port number is usually 42424. The configuration is as follows:

mode="StateServer "

stateConnectionString = " tcpip = 127 . 0 . 0 . 1:42424 "

2.2 Find a server as a session server.

If the IP is:172.18.1.188, start the ASP.NET status service in Windows (the default port number is 42424), and change the startup type to automatic;

2.3 Modify the keys in the session server registry:

The value of the AllowRemoteConnection key in HKEY _ local _ machine \ system \ currentcontrolset \ services \ aspnet _ state \ parameters of the listening port of ASP.NET State Service is1; After the revision, ASP.NET's national service needs to be restarted to take effect;

2.4 the web.configstateconnectionstring of each server points to that server.

Using this mode, the storage of session state will not depend on the failure or restart of IIS process, and the session state will be stored in the memory space of StateServer process.

Third, SQlServer mode.

Another session state mode is SQLServer mode. This mode saves the session state in the SQL Server database. Before using this mode, there must be at least one SQL Server server, and the required tables and stored procedures must be established in the server. Yes. NET SDK provides two scripts to simplify this work: InstallSqlState.sql and UnInstallSqlState.sql

c:\windows\Microsoft。 NET \ framework

To configure the SQL Server server, you can run the command line tool osql.exe provided by SQL Server on the command line.

Osql-s[ server name ]-u[ user ]-p[ password]

For example:

Osql -s (local)-u as-p ""-i installsqlstate.sql.

After completing the necessary database preparation, change the mode attribute of the sessionstate element in the web.config file to "sqlserver" and specify the SQL connection string. Details are as follows:

mode="SQLServer "

sqlConnectionString = " data source = 127 . 0 . 0 . 1; Userid = sa password =; Trusted_Connection=yes "

Using SQLServer mode can make the state of the session independent of IIS server, and can also use the cluster of SQL Servers to make the state storage independent of a single SQL server, which can provide great reliability for the application.