SESSION_ONEND, when can you inspire?
I have encountered similar problems recently, I found a article, I feel some gains, I will post it, give you to see what I want to say, many people may all dismissive. This stuff, I started to do it n-year, and I have a good talk. However, in many places, we will still find some problems, such as some people say, my session_start has stimulated, how session_end didn't work, I did something good after session_end, this can't be done, what should I do?
I have read some articles recently, combined with some of my experience, I want to discuss with everyone.
In fact, many of this type of problems are caused by a thing, it is the session ID. First of all, is it one IE Client? Access a page, as long as I am not a browser, the session ID is the same? Many people will think, it should be the same, my browser has not closed, the web server will always think that I am the same client, and will not change the session ID. To verify this, let's make a simple trial now. Create a simple ASP.NET web app with VS.NET. Add a button on Web Form1, then enable TREFIX on the page. Next to browse this page, keep the Click button to submit the request. Thanks to the ASP.NET of this Trace function, we can see the session ID is actually constant. That is, this time is at the server side, it is not concerned about the existence of this client. Every time it feels that it is from a new client.
What is going on here? OK, let us add a sentence in Page_Load, session ["variable1"] = "testValue"; then do test. Bingo, now the session ID is maintained. I think many people may not pay attention to this. Here we can draw a conclusion: To build a continuous session, we need to use the session variable at least. If you want to use it, you will write at least in Session Dictionary.
However, it is worth noting that this is just a necessary condition, not sufficient condition.
Before mentioning the next necessary conditions, let's first find one thing, if we have global.asax in the middle of the program, there is session_onstart, session_onend, the experiment above is not successful. The reason is that once the session_onstart handler is defined, the session's State will always be saved, even if it is empty, in this case, the session ID will not change. Because sessions still consume resource, if there is no need in the ASP.NET Web App, you don't write session_onstart, session_end in Global.asax.
In the experiment above, we can also see that if the session ID changes, we can't track session_onend, once stable, session_onend appears.
Now, let's talk about another condition, or start from the experiment, we add a sentence on the basis of the example (including session_onstart, session_onend), add one sentence, session.abandon (). Run, 咦, this is where you will find a strange place, Session_onend does not execute, although session_onstart has executed it. (Here we need to write some LOG statements to observe) and if we write session.abandon () in the Button.onClick event, session_onend executes immediately. Strange, what is the difference here? In this way, the second necessary condition is triggered, so that session_onend is successfully executed, at least one request has been completely performed. The first case of the above, if it is stopped in Page_Load, the first request is not executed, and session_onend can't inspire.
To integrate these two necessary conditions, we can finally derive the sufficient conditions to be performed by session_onend: 1) At least one Request successfully executed 2) At least some Data is in Session State. Can be implemented by session variables or add session_onstart.
Last declaration, session_onend is only supported in Inproc mode, that is, support only in the SESSION DATA in ASP.NET WORKER Process.
Originally from: http://www.cnblogs.com/aierong/archive/2004/07/03/20867.aspx