I'm making a series of calls to my web application (IIS7 in Classic mode). The first two calls instantiate objects and place them in the Session object.
By the time I make a third call, the session is missing an object. I expect there to be 2 of my keys in Ses开发者_运维知识库sion, but there is only 1.
It's almost as though there are multiple sessions being created. One thing to note is that this happens a lot, it is not 100% repeatable, i.e. sometimes everything works fine.
The objects are sizeable, but not huge (About 100 small strings) so it seems unlikely that I'm maxing out a session size. I'm not putting any other objects in there.
Sounds like you are expieriencing an unhandled exception, that you are not aware of. The session gets destroyed upon such exceptions.
Set breakpoints in the global.asax to the Application_OnError, Session_End and Session_Start methods to check for them
Ok, I solved it (With the help of the global.asax tip from citronas).
As ever, it turns out that I asserted things in my question and comments that were not as true as I'd assumed.
The first two calls are not actually made in serial, but the second was being made before the first had had time to return. This resulted in two Session_Start calls (Interestingly with the same session ID). The first session data was therefore being overwritten.
Changing my app to wait for each call to return fixed the problem.
Thanks to everyone who answered or commented.
Which one disappeared, the first or the latest added? Your application seems to be recycled after the first call, so the first added will be erased.
精彩评论