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.