Last post Oct 03, 2011 08:31 AM by Nik Raykov
Oct 03, 2011 06:28 AM|Nik Raykov|LINK
I have a flag that I want to be persisted in Session State but the value is lost on subsequest requests if there is an unhandled exception in the application. I have enabled Health Monitoring and the application is not restarted for sure. If the exception
is handled in the Application_Error event or in the page's error event calling either Server.ClearError() or manually redirecting to my error page (not relying on the ASP.NET Framework to do this on its own) the Session data is persisted across requests.
Here is a sample code that shows this scenario:
protected void Page_Load(object sender, EventArgs e)
Session["test"] = "bla bla";
throw new ApplicationException();
Run it in debug mode and you will see that on the second request Session["test"] will be null.
It seems that this might be the default behavior of the framework but I could not find any written statement about it. Can anyone here confirm this or give some explanation if possible?
Oct 03, 2011 07:56 AM|amitatbangalore|LINK
this may help you:
Mark this reply as answer, if you find the links helpful.
Oct 03, 2011 08:31 AM|Nik Raykov|LINK
There is no app restart as I've already mentioned. I've already read these but there's no real explanation of the problem except for the first link that has quote of some MS MVP saying some major unhandled exceptions cause session loss.
I am looking for an explanation why this is happening not reasons for applications to restart and on and on. This is not the case so if anyone is aware whether this is the default behavior I'd appreciate his/her feedback.