Configuration scheme for sessionstate nodes in Web. config web.sessionstate nodeConfiguration scheme, sessionstate hasfive different modes: Custom,off,inproc,stateserver,sqlserver.
1. Custom Mode
Session state uses the custom data store to store session state information.
2. off Mode
Literally you can see that this is a closed mode, if the current page does not need the value of the session, in order to reduce the server resources, you can remove the session overhead.
<sessionstate mode= "Off" > or on the page
<%@ page enablesessionstate= "false"%> to close the session.
3. inproc Mode (default mode)
It allows "cookie-free" sessions, as well as storage outside the server
Session data. Asp. NET session state module is configured in the Web. config file as follows:
<sessionstate mode= "InProc" cookieless= "false" timeout= "/>"
In this example, the Mode property is set to InProc (the default), which indicates that the session state is to be stored in memory by ASP.
No cookie is used to pass the session ID. In this way, no cookie or hidden form fields are unnecessary.
So, even if you don't use a form in your Web page, you can join a conversation. But this way, the state of the application will depend on the ASP. NET process, when the IIS process crashes or restarts normally, save the
The status in the process is lost.
4. StateServer Session Management mode
Set the Mode property to StateServer, which is to store session data in a separate memory buffer and run on a separate machine
Windows services to control this buffer. The status service is the full name of the "ASP. Aspnet_state.exe", and the service is visible in the Computer Management-service, starting the service
It is configured by the stateConnectionString property in the Web. config file. This property specifies the server on which the service resides, and the
Port of view:
<sessionstate mode= "StateServer"
Stateconnectionstring= "tcpip=myserver:42424"
Cookieless= "false" timeout= "/>"
In this example, the State service runs on port 42424 (the default port) of a machine named MyServer. To change on the server
Port, you can edit the port value in the Hkey_local_machine\system\currentcontrolset\services\aspnet_state\parameters registry key.
Obviously, the advantage of using a state service is process isolation and can be shared in a Web farm (site farm). With this mode, session state storage will not
Depending on the failure or restart of the IIS process, all session data will be lost once the state service is aborted. In other words, the state service does not
The data is persisted as SQL Server does, and it simply stores the data in memory.
5 Session Management with SQL Server
Asp. NET also allows session data to be stored in a database server by turning the Mode property into SQL.
In this case, ASP. NET attempts to store session data in the sqlConnectionString attribute (which contains the data source and the logon service
Security credentials required by the server.
In order to configure SQL erver with the appropriate database objects, the administrator also needs to create the ASPState database.
Method is to run the InstallSqlState.sql script in the Windir\microsoft.net\framework\version folder (windir is the service
Windows folder, and version is the installation folder for the. NET Framework version you are using.
To configure a SQL Server, you can run SQL Server-provided command-line tools on the command line Osql.exe
osql-s [Server name]-u [user]-p [Password]-I installsqlstate.sql
For example
Osql-s (local) \netsdk-u sa-p ""-I InstallSqlState.sql
Here the user name must be the SA account on the SQL Server, or another account with equivalent permissions. Interested readers can open the
This script file to understand how ASP. NET implements state management with SQL Server.
To unload these tables and stored procedures, you can use the UninstallSqlState.sql script, similar to the previous method. After you have done the necessary database preparation, change the mode of the sessionstate element in the Web. config file to "SQL Server" and specify the SQL connection string. Specific as follows:
mode= "SQL Server" sqlconnectionstring= "Data source=127.0.0.1; Userid=sa; Password= "
When SQL Server is configured, the application code runs with no difference from InProc mode. Note, however, that because the data is not stored in local memory, objects that store session state need to be serialized and deserialized to pass through the network to the database server and back from the database server. This will of course affect performance. By storing session state in the database, you can effectively balance performance for scalability and reliability, respectively. In addition, you can leverage the SQL Server cluster so that the state store does not rely on a single SQL Server, so that you can provide maximum reliability for your application.
Configuration scheme for sessionstate nodes in Web. config