views:

45

answers:

1

Hello,

I have health monitoring enabled on a production system (asp.net webforms .net 4) and I see that there's a lot of errors being sent to me indicating that a session variable has been lost.

(I am trying to attach something out of session state to a entity framework data context and get a "Value cannot be null, parameter name entity" error). So somehow the session variable now contains null and not an object.

Interestingly we have the same application deployed on two separate servers - one DMZ server for external users and one internal server for internal users. Both of these applications on two different servers seem to have the same problem.

Health Monitoring is also monitoring lifetime events and I can see from this that we do not have something like IIS recycling, config changes, changes to bin folder, recompilations etc, occuring.

I've read this page: http://weblogs.asp.net/bleroy/archive/2004/08/03/Don_2700_t-redirect-after-setting-a-Session-variable-_2800_or-do-it-right_2900_.aspx

I can confirm that it's not a Response.Redirect problem because that's not happening - this is an online application form - it puts an object in session state on page_load and there's a multiview - when "next" is pressed, the object comes out of session state, is attached to the data context, changes are made from the web form and the datacontext updated. So there's no response.redirect happening.

I can also confirm the details in "Update 1" and "Update 2" from that link are not relevant to me - there is only 1 worker process running in the application pool and the server name or web address do not contain underscores.

I also persued the possibility of session timeouts occuring but they should be handled by other code which is running to detect session timeouts (see: http://blogs.msdn.com/b/nikhiln/archive/2007/06/21/detecting-session-timeout-in-asp-net-2-0-web-applications.aspx ) which I have tested over and over - Part of the problem is I just cannot reproduce this error myself.

So:-
- Not timeouts
- Not the IIS worker process recycling or any other thing which would generate a Health Monitoring lifetime event
- Not using response.redirect
- Not got a web farm/multiple worker processes

I then found this thread: http://bytes.com/topic/asp-net/answers/490975-disappearing-sessions where an MVP said the following:

Anytime the IIS application is restarted, all sessions are restarted too. So yes, this would generally happen during recompilations and some major unhandled application level exceptions.

But sadly didn't elaborate what sort of "major unhandled application level exceptions" might lead to session loss - this is a brand new system and we do still have unhandled exeptions that we're working on fixing - so what sort of exceptions are we talking about here? Can an application exception in one person's session really delete all sessions held by the application?

This thread also touches on it: http://bytes.com/topic/asp-net/answers/490975-disappearing-sessions

The only thing I've seen similar is when a runtime error occurs in the ASP.NET application, causing the application to restart. Are you receiving Application_OnStart events too?

So I'm guessing if I had a runtime error that caused the application to restart, that would also generate a health monitoring lifetime event, right? And I'm just not getting any of those...

It would be a lot easier if I could actually repro this but I just cannot!

Anyway sorry for a long rambly question, just hope somebody has some ideas.

Regards

A: 

Did you consider placing session state outside the app, e.g. with any of the asp.net out-of-process modes for session state?

By default, session state is maintained inside your app. It is not available across multiple servers, nor is it maintained across application crashes (i.e. any unhandled exceptions in your app.)

  1. Use the SQL Server mode to make the same session state available across multiple servers.

  2. Alternatively, if your load balancer guaranties strong session affinity, you can use the asp.net state server to manage state in each server in a way that lets state survive application restarts.

Oren Trutner
Thanks. I'll give it a go.
bgs264
Hi. Thanks for your comment, we moved session state out of process in an update this morning (to the ASP.net state server) but unfortunately it has not fixed the problem. We are still having session variables getting lost.
bgs264