How to recognize that Session_OnEnd event raises because of Application end in MVC Application

431 Views Asked by At

In my ASP.NET MVC4 application I have Session_OnEnd and Application_End events. When application ends Session_OnEnd events called firstly, after that Application_End called. Is there a way to recognize in Session_OnEnd event that its happening for the reason that application is ending?

1

There are 1 best solutions below

0
On BEST ANSWER

During Session_End, there is no way to know the reason for the event being raised. If your logic is to save off data, can you cache it somewhere (with an expiry) and pick it up in the Application_End?

So if it is Application_End scenario, retrieve the cached data do whatever you need to do.

Otherwise, the cache expires after 'x' amount of time and no harm done.

Over of caching in ASP.NET: https://msdn.microsoft.com/en-us/library/aa478965.aspx