Lost ASP.NET Session Variables

I have a solution that includes 2 projects and 2 class files that are called by reference. In one of my projects, I have the code in Global.asax in the Session_Start block, which loads several variables from the database and sets them into session variables. If I set a breakpoint in Global.asax, I can check if the variables are really set correctly.

When I refer to session variables in classes in any of my code or class modules in my project, they are. But if I refer to them in one of the classes that is called by reference (essentially a common class), the session variables are all zero.

I use HttpContext.Current.Session ["varName"] to access the variables in the class, as is standard.

Is there anything else I need to have access to these session variables? Could this be a namespace problem?

+4
source share
2 answers

I had the same problem earlier, I continue to lose my session variables (although not in the same context as yours). I found these articles useful for my problem: Example for ASP.NET: lost session variables and reprocessing appdomain and PRB: session data is lost when using ASP.NET InProc session state mode . Hope this helps too. Hooray!

+3
source

Are you calling Session.Abandon () anywhere in the code? I did this at the beginning of my web application to make sure I started with a fresh session. It turns out that any session variables stored even after "Abandon" will be deleted (even if SessionID was forced to remain unchanged by other means, for example, using Server.Transfer (Url, true) and not Response.Redirect), after postback .

i.e. I could track in my application, observe all session parameters, and then at the moment when any event handler was called (something with AutoPostBack = "True", for example, a checkbox or button on UpdatePanel), BAM, I had same SessionID but null session variables.

Removing the proactive call to Session.Abandon () solved my problem right away.

Jeff

+3
source

All Articles