views:

99

answers:

2

We have a strange problem occurring once in a while on our servers. It usually happens when one or more of our web applications are upgraded. Debugging the problem has gotten me this far...

During the processing of a request:

  • In the ASP.NET application we put an object in session
  • In code running later (same request) we look up that same session value. It's empty!

So it looks like the session service isn't working, right? This code runs hundreds of times a day, and never fails in development environments or in production situation, only related to upgrading the web application(s) on the web server.

And the strange thing: We haven't really fond a proper way of fixing the situation either. IIS reset, ASP.NET state server stop/start, web.config edits, and even server reboots have all bin used - normally a combination is needed to fix it + plus a lot of swearing and pulling of hears. And in most cases it isn't fixed right away, but maybe two or three minutes after the third IIS reset or whatever. (So it might not be what fixed it after all.)

I'm going crazy here. Any ideas what might be the problem? Is it a microsoft bug?

Some more info:

  • We're running under .NET 2.0
  • We are using the ASP.NET state service
  • The code accessing the session variable and getting back null is in an assembly referenced by the ASP.NET app. It uses the HttpContect.Current to get at the session
A: 

Can you consider not using a session variable?

If you need the data in the same session, you can use HttpContext.Items which is much more lightweight than using a session variable.

Answering to your question: Maybe the session is not created yet when you access it for the first time. It will throw an exception if it does not exists.

Check for

If Not IsNothing(Context.Session) Then
    'do something
end if
Eduardo Molteni
No, the session is there, and accepts my variable, it's only gone when I try to retrieve it. And I need the session - and it works in 99,999% of the times.
Torbjørn
+2  A: 

HttpContext.Items are only available during the lifetime of the request not the entire session, so that needs to be considered.

To answer the original question,

  1. When you add the item to session can you retrieve it successfully in the next line?

  2. Is it server specific? i.e. One server can see the value in session but not the other?

  3. The dll that is trying to access the variable, is there any platform target difference on it, for .e.g. .net 1.1 vs .net 2.0?

Sijin
Point 1 - that will be the next thing I try. Point 2 - don't understand. Everything runs on single server actually. Point 3 - everything should have been compiled and be running under .net 2.0.
Torbjørn
I was just able to test what you suggested in Point 1. And that actually worked, so the session isn't totally gone. Stranger and stranger...
Torbjørn