I am in the process of upgrading a project to a newer version of Visual Studio, .Net Framework and our masterpage for the application. Unfortunately, when doing this, some of the code no longer works.
On my default.aspx.cs page, I am setting a session variable: Session["user"] = sUser;
I need to access this session variable in a security.cs file (not a code-behind). Unfortunately, every time I try to access this: string sUser = HttpContext.Current.Session["user"].ToString();
I am getting a "'HttpContext.Current.Session["user"]' threw an exception of type 'System.NullReferenceException'" error.
I understand that by design, a class file doesn't have access to Session, but I am hoping there is some way I can access this to save me a lot of work. If I cannot access Session, I will need to change a lot of code to pass around the user into a bunch of class files. If I can somehow use session (or some other method to set in the page_load of the default.aspx.cs file), the change will be very minor.
Is there someway to make this work?