I have a solution which includes 2 projects and 2 class files that are called by reference. In one of my projects, I have some code in Global.asax in the Session_Start block that loads a few variables from a database and sets them into session variables. If I put a break point in the Global.asax I can verify that the variables are in fact being set correctly.
When I reference the session variables in classes in any of my code-behind modules or a class in my project, they are there. But if I reference them in one of the classes that is called by reference (a shared class, essentially), the Session variables are all null.
I am using HttpContext.Current.Session["varName"] to access the variables in a class, as is standard.
Is there something else I need to consider to have access to these session variables? Could it perhaps be a namespace issue?
ASP.NET is an open source web framework, created by Microsoft, for building modern web apps and services with . NET. ASP.NET is cross platform and runs on Linux, Windows, macOS, and Docker.
. NET Framework is an object oriented programming framework meant to be used with languages that it provides bindings for. Since C is not an object oriented language it wouldn't make sense to use it with the framework.
ASP.NET is a web application development framework used to develop web applications using different back-end programming languages like C# where C# is used as an object-oriented programming language to develop web applications along with ASP.NET.
NET Common Language Runtime, allowing web pages to be coded in VB.NET, C#, J#, Delphi.NET, Chrome etc. This means you don't have to learn C# to use it and, even if you don't know any of those languages, you may find it easier to start with a more human readable one such as VB.NET.
I had the same issue before, I keep on losing the my session variables (although not in the same context as yours). I found this articles helpful for my issue: ASP.NET Case Study: Lost session variables and appdomain recycles and PRB: Session Data Is Lost When You Use ASP.NET InProc Session State Mode. Hope it might help you too. Cheers!
Are you calling Session.Abandon() anywhere in the code? I was doing this at the start of my Web App to ensure I was starting with a "fresh" session. Turns out that any Session variables stored even after the "Abandon" would be dropped (even if the SessionID was forced to remain the same via other means, such as using Server.Transfer(Url, true) rather than Response.Redirect), upon postback.
i.e. I could trace into my app, watch all the session variables be correctly set, and then the moment any event handler (anything with AutoPostBack="True", like a checkbox or button on an UpdatePanel) was called, BAM, I had the same SessionID, but zero session variables.
Removing the pre-emptive call to Session.Abandon() solved my problem straightaway.
Jeff
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With