Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.NET session ends unexpectedly

I am having a very weird issue with session on ASP.NET 2.0. The system I'm working on uses session variables to store parameters on objects (Like Questions and Answers) for generating a report. These are instances of classes of the same name, and so they're populated with parameters as follows:

This report is generated throught 4 aspx pages. First defines location and date parameters, second page stores questions, and third stores answers. The last displays links to generated reports on Excel and HTML formats. All variable data is stored on session, and everything goes well, until the last page, when something like a Session.Abandon() happens, Session_End event is fired and all variables are lost. This happens only once a day, for each logged user on the first use of the report, and then you can try the whole day dozens of times and won't see it again.

The issue happens on the same page ALWAYS, and session mode is InProc.

I have already done the following validations:

  1. Checked if there were any Session.Abandon() or Session.Clear() commands. There are none.
  2. Checked session timeout, it's set to 18 minutes, and the issue happens anytime as stated above, regardless of how long you've been using it withint 18 minutes.
  3. Checked forms timeout, under Authentication. It's also set to 18 minutes.
  4. I have learned that there's a bug with Server.Transfer() that might sometimes flush session and viewstate, and have replaced with Response.Redirec()
  5. Have monitored session line by line of code, and everything goes well, and when the page is fully loaded it simply dies. All variables are gone, but session is still working.
  6. As far as I'm concerned, IIS is correctly configured. I don't have access to it, but all other systems work perfectly.
  7. Have also analysed some of the aforementioned systems looking for some clue on what could be happening, but their web.config files are very similar to the one I'm having the issue, and no special code is implemented to interact with session differently.
  8. Also thought about monitoring IIS for application restarts, but I'm pretty sure it's not exceeding the default limit of 15. Nevertheless, I don't have access to IIS server, and all testing done on my computer is using ASP.NET Development Server. The issue occurrs on both.
  9. Have checked possibilities of process recycling, like .config and asax file changes, changes to/on bin directory, none happens.

Following restrictions apply:

  1. Can't change session mode to other than InProc due to company policies.
  2. The report generation "process" was created through 4 pages. I disagree with this, but can't redo it due to time and budget restrictions.

Any thoughts or solutions are helpful. I'll keep in touch for any updates and tests made necessary.

like image 793
Alexandre Fernandes Avatar asked Jun 28 '11 14:06

Alexandre Fernandes


2 Answers

I'd like to thank everyone for the effort!

Me and my team discovered what was happening on this case. There was a method that was deleting temporary files and directories within the Website folder, causing a recycling and session flush. The code was calculating date and time, and was supposed to delete the dirs every 24h, so when a user first logs into the system and generates the report, it deleted the dir and flushed the session.

like image 91
Alexandre Fernandes Avatar answered Dec 13 '22 04:12

Alexandre Fernandes


A couple of suggestions:

  1. Debug the first hit locally and see if there is anything unique in the path.
  2. Make sure the first hit is not causing an issue with the worker process
  3. Make sure you are not using the session value before a postback

What I think is happening is #3. You are setting up the values in a session and then consuming them back out of that session before a postback, where the session value is actually stored. Since it is only happening on the first try, the symptoms mirror this suspicion. If I am correct, you solve this by consuming from the same place you consumed the session value rather than set session and then try to pull from it in the same request.

like image 22
Gregory A Beamer Avatar answered Dec 13 '22 04:12

Gregory A Beamer