Session variables lost - Singleton instance becomes null

normajean

New Member
I'm working on a Web app using ASP.NET. I have a class called "Sistema" that uses the Singleton pattern.When the instance of Sistema is created, the database connection is opened and a process runs that loads some static information for later use. This lasts almost 2 minutes.\[code\]private static Sistema instance;private Sistema(){ OpenDataBase(); LoadStaticInformation();}public static Sistema GetInstance(){ if (instance == null) { instance = new Sistema(); } return instance;}\[/code\]On my Web App I have a Master Page that controls if the user is logged in by checking a Session variable. If this Session is null, then the user is sent to the Login Page.On the Login Page, the first thing I do is to check if the instance of "Sistema" is null. If it is, then when the user hits the Submit button, a message is shown saying "Login can take up to two minutes. Please wait". If it is not null, then no message is shown as the login action takes only a couple of seconds.I have been told by the users, that when going through the System, they are sometimes sent back to the login page, and when they try to login, the message saying "Login can take up to two minutes" is displayed and login indeed takes a while.The fact that they are sent back to the login page means that the Session variable is lost, and the message being displayed means that the instance of "Sistema" is also null.In order to determine why this is happening, I created a web page that sends an email to me when the instance of Sistema detected to be null. I thought that if I was able to know when this occurred, I might discover what is going on.This web page is really simple. It runs every 10 minutes and checks if the instance of Sistema is null. If it is, then an email is sent and the instance of Sistema is created. \[code\]bool isInstanceNull = Sistema.IsInstanceNull();if (isInstanceNull){ String emailTo = "..."; String emailContent = "..."; Functions.SendMail(emailTo, "Sistema is null", emailContent, ""); Sistema.GetInstance(); Functions.SendMail(emailTo, "Sistema has been created", emailContent, "");}\[/code\]The only thing I discovered is that it's not happening at a specific time. For example, last week it happened around 7pm, but today it happened at 2 am. Regarding the Session timeout, I'm using a solution in the code behind: http://www.beansoftware.com/ASP.NET-Tutorials/Keep-Session-Alive.aspx.Any suggestions to why is this happening?
 
Back
Top