Session-Lost Solution summary _win Server

Source: Internet
Author: User

sessionstate timeout), the main reason for this is three kinds

One: Some kill virus software will go to scan your Web.config file, at that time session affirmation drops, this is Microsoft's saying.
Two: Inside the program has let session loses the code, and the server memory is insufficient to produce.
Third: The program has frames page and cross domain situation.

The first solution is to make the virus-killing software screen scan the web.config file (not to edit it when the program is running)
The second is to check whether the code has Session.Abandon () or not.
The third is to start the ASP.net State Service in the window service.

Today encountered ASP.net session lost, and then came back, the session is stored in the user information, and finally caused each refresh is different users or not logged in state. It's a problem that makes people bleed.
2 days did not get out, and finally rewrite the verification mechanism, are placed in the cookie, the session is not used.
Today, the problem is due to the maximum number of web processes within the performance of the set IIS6 application pool, because the session defaults to the Web process, the process is much more open, resulting in sessions that cannot be shared, and each refresh is handled by different processes. This results in refreshing the different users, provided they are logged on to this computer.
Workaround you can use StateServer or SQL Server mode to store the session.
Because Google did not search a similar issue, so here to say this let me headache for 2 days, and finally modified the N-page problem.

asp.net session lost online collection
asp.net default configuration, the cause of the session inexplicable loss and solutions
Session will be lost for no reason under normal operation. Because the program is constantly being manipulated, excluding the possibility of session timeout. In addition, the session timeout is set to 60 minutes and will not be timed out so quickly.

This time to csdn to search a post, found that a lot of people are discussing this issue, and then I Google again, found that Microsoft has similar content on the site.

Now I'm going to write out the reason and the solution.

Reason:
Because the ASP.net program is the default configuration, the session setting in the Web.config file is as follows:
<sessionstate mode= ' InProc ' stateconnectionstring= ' tcpip=127.0.0.1:42424 ' sqlconnectionstring= ' data source= 127.0.0.1; Trusted_connection=yes ' cookieless= ' true ' timeout= '/>

We will find that there is an attribute mode in the sessionstate tag, which can have 3 values: InProc, StateServer? SQL Server (case sensitive). By default, it is InProc, which means that the session is stored in the process (IIS5 is aspnet_ Wp.exe, and IIS6 is W3wp.exe), this process is unstable, and when certain events occur, the process is reset, causing the session loss stored in the process.

Under what circumstances will the process be reset? An article from Microsoft has told us:
1. memorylimit attribute of processmodel label in configuration file
2, Global.asax or Web.config files are changed
3, the Web program (DLL) in the Bin folder was modified
4, antivirus software scanned some. config file.
For more information please refer to prb:session variables are lost intermittently in asp.net applications

Solution:
The mode attribute in the sessionstate label mentioned earlier can have three values, except for InProc, which can also be stateserver, SQL Server. These two methods of saving the session are all out-of-process, so when the aspnet_wp.exe is reset, it does not affect the sessions.

Now, set the mode to StateServer. StateServer is a service on this computer that can see services in the system service named ASP.net State Service, which is not started by default. When we set mode to StateServer, please start the service manually.

In this way, we can use the local stateservice to store the session, unless the computer restarts or Stateservice collapsed, the session will not be lost (due to the session timeout is discarded is normal).

In addition, we can also save the session through the stateservice of other computers. The specific changes are as follows. Also in the sessionstate tab, there is a stateconnectionstring= ' tcpip=127.0.0.1:42424 ' attribute with an IP address, which defaults to native (127.0.0.1), You can change it to the computer IP that you know is running the Stateservice service, so that you can realize the ASP.net program on different computers.

If you have higher requirements and you need to have a session not lost during the service restart, consider setting mode to SQL Server, as well as modifying the sqlConnectionString attribute. For an operation to save a session using SQL Server, visit here.

When you use StateServer or SQL Server to store sessions, all objects that need to be saved to the session must be serialized in addition to the basic data type (the default data type, such as int, string, and so on). Just put the [Serializable] label in front of the class you want to serialize.
Such as:
[Serializable]
public class MyClass
{
......
}
Specific serialization-related knowledge please join here.

So far, the problem is solved.
A summary of the problem of ASP.net session loss
How the session works in asp:
The ASP's session is process dependent. ASP session state is stored in the process of IIS, that is, inetinfo.exe this program. So when the Inetinfo.exe process crashes, the information is lost. In addition, the restart or shutdown of the IIS service can result in loss of information.

The realization of ASP.net session
asp.net session is based on HttpModule technology, HttpModule can be processed before the request to the State control of the request, because the session itself is used to do state maintenance, so with HttpModule to do the session is more appropriate.

Reason 1:
The files in the bin directory are overwritten, ASP.net has a mechanism that, in order to ensure that the system works correctly after the DLL is recompiled, it will restart the Web site process, which can cause session loss, so if an Access database is in the bin directory or if other files are overwritten by the system, the session is lost

Reason 2:
Folder Options, if the Open folder window in a separate process is not turned on, once you create a new window, the system may think it is a new session conversation, but you cannot access the original sessions, so you need to turn on this option, which will cause session loss

Reason 3:
It seems that most of the session loss is caused by the client, so to start from the client to see if the cookie is open

Reason 4:
Session time setting is not a problem, will not cause loss due to timeout

Reason 5:
The number of cookies in IE (20 cookies per domain) may cause session loss

Reason 6:
Use the Web garden mode and use InProc mode as a way to save the session

Resolve lost Experience
1. To determine if the reason is 1, you can keep track of the modification time of a file in Bin
2 each time you refresh the page. Do the session read and write log, every read and write session to record down, and to record SessionID, Session value, the page, the current function, the number of sessions in the function, so it is convenient to find the reason for the loss of a lot of
3. If allowed, it is recommended that you use state server or SQL Server to save the session so that it is not easily lost
4. Add code to record the creation time and end time of the session in Global.asa, and the loss of sessions due to timeouts can be recorded in Sessionend.
5. If you use client script in some code, such as JavaScript to maintain session state, try to debug the script, because a script error causes session loss

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.