The errors that I am getting all relate to apparently uninitialised session variables, namely: “System.NullReferenceException: Object reference not set to an instance of an object”. After lots of checking, I have come to the conclusion that the server is somehow losing the session variables or that the absence of any SQL table locking during these updates might be involved.
When users first log in, they land on what I call the “User Home Page”, which sets defaults for the session variables. Unfortunately, if the session times out and the user later tries to continue working, the ASP.NET system logs him in again and takes him straight back to the page he was working on previously. This means that the session variables are not set because the user did not get there via the User Home Page. To solve this, I added the following code to the top of the User Home Page:
Expand|Select|Wrap|Line Numbers
- if ((Session["TimeOut"] != null) && (Session["TimeOut"].ToString() != "False"))
- {
- Time_Out_Label.Text = "Suitable error message";
- }
- Session["TimeOut"] = "False";
Expand|Select|Wrap|Line Numbers
- if (Session["TimeOut"] == null)
- {
- Session["TimeOut"] = "True";
- Response.Redirect("../Members/user_home.aspx");
- }
It seems to work, in that if I allow the session to time out and then attempt to continue, I get transferred to the User Home Page (with the intended error message) instead of having everything collapse in a big heap when the code tries to access an uninitialised session variable on the page that the user was attempting to view.
The problem is that I also occasionally get transferred to the User Home Page in this way during normal operation, i.e. within a few seconds of executing some other action, when clearly the session should not have timed out. I guess that in one sense this is good news, because it means that the original uninitialised-variable error messages were not due to errors in the code, but why are the session variables being forgotten by the system?
The site is hosted on a shared server at One and One. I’ve since been wondering what the server does if it runs out of storage space for session variables. Does it just kill off a few? Maybe at busy times, it doesn’t like my organisation chart editing process, which could involve several hundred separate database accesses for a single page update and therefore it simply kills the process (and the session variables). I have checked the entire project and there are no other references to "TimeOut" anywhere in the code.
Any ideas would be very much appreciated.
ChrisAtWokingham