Session bug Modification

Source: Internet
Author: User

[Test Site]
Multiple methods for saving session in ASP. NET.
[Occurrence frequency]
★★★☆☆
[Answer]
Use in-process session Status Mode
If the aspnet_wp.exe or application domain restarts, session status data will be lost. It can be stored in sate server or SQL Server database.
Store the session name/value pair set. However, these methods are less efficient and cannot capture the end event of the session.
[Analysis]
This topic is used by the examiner to determine whether the session data is lost because the session data is lost when the aspnet_wp.exe process or application domain is restarted. The cause may be:
Modified the global. asax file.
Modified the Web. config file.
Change the bin directory path of the Web application.
Anti-Virus Software scans (which may be modified) files in the global. asax file, Web. config file, or bin directory of Web applications.
In the <processmodel> element of the web. config configuration file, you can set the attributes that cause the new process to start when the conditions are met, but this is not a bug.
In ASP. NET applications, the session settings in the web. config configuration file are as follows:
<Sessionstate mode = 'inproc'
Stateconnectionstring = 'tcpip = 127.0.0.1: 8080'
Sqlconnectionstring = 'data source = 127.0.0.1; trusted_connection = Yes 'cookieless = 'true' timeout = '60'/>
To
The <sessionstate/> node in the above Code has a "Mode" attribute. Its values can be "inproc", "StateServer", and
"Sqlserver". The default value is "inproc ". The specified value indicates that sessionis included in the process (iis5is aspnet_wp.exe, and IIS6 is
W3wp.exe), the process may be restarted when some unexpected events occur in the system, resulting in the loss of sessions stored in the process. If the value of the "Mode" attribute is
"StateServer" or "sqlserver" can avoid the loss of the session value after the process is restarted, because the two methods store the session value outside the process.
First
First, change the "Mode" attribute to "StateServer ". StateServer is a local network service. In the Service Manager, you can see the name
The "ASP. NET State Service" service is disabled by default. If you want to use StateServer to store session values
After the "Mode" attribute is changed to "StateServer", the programmer needs to start the "ASP. NET State Service" service. Click
In Windows XP, select the "Start" menu, select the "run" command, enter "services. msc", and click "OK" to open the Service Manager and find
11.3, and start the service. Figure 11.3 start the ASP. NET State Service
In addition to starting the service using a graphical interface, you can also enter the command shown in the following code in the command line to start the service.
Net start aspnet_state
Now
The programmer can use the local StateServer method to store the Session value, unless the server is restarted or the "ASP. NET State Service" Service
Stop. Otherwise, the Session value can exist stably within the timeout period. Programmers can also pass the Session value through the "ASP. NET State Service" of other computers"
You only need to modify the attribute of "stateConnectionString" in the <sessionState/> element
Other computers, and start the "ASP. NET State Service" Service on other computers. With this operation, programmers can make
ASP. NET applications share Session values.
If the Session value of a WEB application requires better persistence and reliability
The Session value is not lost. You can change the "mode" attribute to "SQLServer ". Besides, you also need to modify the sqlConnectionString attribute,
To ensure correct connection to the SQLServer database. Microsoft provides an SQL script file to create a database that stores Session values. The database name is ASPState, which contains a large number
Resources called by the ASP. NET Runtime Library (such as stored procedures ). Although it is reliable to store the Session value in the database, it is slow.
Note: To store Session values using non-in-process methods, make sure that the custom type in the HttpSessionState object is Serializable, that is, the type is marked with the [Serializable] feature.

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.