Solution to session failure

Source: Internet
Author: User
Recently, many problems have been found on the most e-commerce website, but they have all been solved smoothly. The session issues are recorded as follows for future reference. We also hope to help our netizens, the content of this article is not entirely from myself. It is my work on some handling methods on the Internet.

  • The default value is 20 minutes. The value is set to session. Timeout = 30. Or you can set it to a higher value. The unit of the value is minute, depending on the situation.
  • CheckCodeWhether session. Abandon () or not. Once the abandon method is called, the current session is no longer valid and a new session is started.
  • ASP. NET uses the ACCESS database, and the database is placed in the bin directory. The solution is not to put the updated files in the bin directory.
  • The same session can be continued only when the same page is uploaded to another page, that is, the sessionNot cross-OriginAt the same time, when the client closes the browser or closes the browser page session, it also disappears. When the client accesses the page again, a new session will be created, but it will survive on the server and wait for timeout, but the call will not be reached. in addition, for example, set the session on the first page, and then redirect the second page.The solution is to set endresponse to false in redirect.
  • Cause of IFRAME session loss: the session is jointly authenticated by the client and the server. The client storage ID is sent to the server by the hair appended to the page for identification by the server, if the conditions are met, the corresponding session operation permission can be obtained.
  • However, if the page is from the framework, and the parent page and framework of the framework are not a site, the client will not attach header information to the page by default, in this way, the server cannot identify the pages in the client framework and cannot operate sessions. Solution:Response. addheader ("p3p", "cp = CaO PSA our ")'Or in the window serviceASP. NET State Service Startup.
  • Some antivirus software will scan your web. config file. At that time, the session will definitely drop. This is Microsoft's statement. Solution: Disable the antivirus software to scan the web. config file (ProgramDo not edit it at runtime)
  • Asp.net's default configuration causes and solutions for inexplicable session loss
    Under normal operation, the session will be lost for no reason. Because the program is constantly being operated, the possibility of session timeout is ruled out. In addition, the session timeout time is set to 60 minutes, and will not time out so quickly. I searched the post on csdn this time and found many people discussing this issue. Then I googled it and found similar content on Microsoft's website.
    Now I will write down the cause and solution.
    Cause:
    Because the Asp.net program is configured by default, the session settings in the web. config file are as follows:
    < Sessionstate Mode = 'inc' stateconnectionstring = 'tcpip = 127.0.0.1: 42424 'sqlconnectionstring = 'data source = 127.0.0.1; trusted_connection = Yes 'cookieless = 'true' timeout = '60'/>
    The sessionstate label has an attribute mode. It can have three values: inproc and StateServer? Sqlserver (case sensitive ). The process is unstable. When some events occur, the process restarts, causing the loss of sessions stored in the process.

    Under what circumstances will the process be restarted? Microsoft Article Told us:
    1. memorylimit attribute of the processmodel label in the configuration file
    2. The Global. asax or web. config file is changed.
    3. The web program (DLL) in the bin folder is modified.
    4. Anti-Virus Software scanned some. config files.
    For more information, see PRB: Session variables are lost intermittently in ASP. NET applications.
    Solution:
    In the sessionstate label mentioned above, the mode attribute can have three values: StateServer and sqlserver. The two session types are both external, so when aspnet_wp.exe is restarted, the session will not be affected.
    Set the mode to StateServer. StateServer is a service on the local machine. You can view the service name in the system service ASP. NET State Service Is disabled by default. After we set the mode to StateServer, manually start the service.
    In this way, we can use the stateservice of the Local Machine to store sessions. The session will not be lost unless the computer restarts or the stateservice breaks down (it is normal that the session is discarded due to session timeout ).
    In addition, sessions can be saved through stateservice on other computers. The specific modification is as follows. Also in the sessionstate label, there is a stateconnectionstring = 'tcpip = 127.0.0.1: 8080' attribute, where there is an IP address, the default is the local machine (127.0.0.1 ), you can change it to the IP address of the computer that runs the stateservice service as you know, so that the Asp.net program located on different computers can communicate with each other.
    If you have higher requirements and the session is not lost when the service period is restarted, you can set the mode to sqlserver and modify the sqlconnectionstring attribute. For the operation of saving sessions with sqlserver, when using StateServer or sqlserver to store sessions, all objects to be saved to the session except basic data types (default data types, such as int and string) must be serialized. You only need to put the [serializable] label before the class to be serialized.
    For example:
    [Serializable]
    Public class myclass
    {
    ......
    }
  • 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.