Asp.net session expired

Source: Internet
Author: User

If you find that the session is suddenly lost for no reason, when you seriously checkCodeAnd you may be close to a crash like me if you want to eliminate the possibility of other common losses ~!

Later I found the problem was that I used code to create a temporary directory and then deleted the temporary directory.

Now I want to share with you the following: I hope it will be useful to friends who encounter similar nails ......

To put it bluntly, the essence of session loss is: ApplicationProgramRestart!

When will the application automatically restart?

For more information, see Anand published in dotnetindia.com.Article

That is to say, Asp.net will monitor the application directory. Once the monitored action occurs (for example, the config and directory are modified) the application will automatically restart. Of course, your session will be lost.

If this operation cannot be avoided (for example, renaming a directory), we can store the information in a cookie or in a database;

Note: In addition to the English conditions listed above. The internal mechanism of session.asp.net will be lost in the directory deletion operation. Treating the directory is a bit like a miser. It is stuck in the directory, and you will not care about it when you create it (add to the directory ), once it is created, it will monitor the directory. If you want to delete or rename it (change its Directory), it will restart ......

2. session loss in Frame

During development, we often use frame to work, and sometimes to integrate with other websites and apply it to multiple domains, IFRAME cannot save the session. Therefore, you can find many related articles online. configuration in config: <sessionstate mode = "StateServer" stateconnectionstring = "TCPIP = 127.0.0.1: 42424" sqlconnectionstring = "Data Source = 127.0.0.1; trusted_connection = yes "cookieless =" false "timeout =" 40 "/> change cookieless =" false "to" true. But there is also a small problem, that is, if the page uses the Javascript window. location. if href = ''is used for redirection, the system considers this as another new request and generates a new sessionid, causing the same loss of the original session. Therefore, it is better to use response. Redirect () for redirection.

In addition to the problem of session loss in ifrmae, frameset also has the same problem. Frameset problems are more specific, sometimes lost, and sometimes not lost. This is a headache. I found a method on the Internet and added a statement in page_onload on the page: response. addheader ("p3p", "cp = CaO PSA our"); the session loss problem in frameset is solved.

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.