3

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?

  • 2
    Maybe add some attribute session related inside the Application_End method, then check inside Session_OnEnd weither this attribute is set or not. – Hybris95 Apr 24 '15 at 08:10
  • 1
    Ummm, why? What are you trying to do that you think you need to know that the application is ending when `Session_End` is invoked? – Luaan Apr 24 '15 at 08:24
  • 1
    Application_End fires after Session_OnEnd. I need to make some logic in Session_OnEnd depending if application is ending or not. – Irina Shyronosova Apr 24 '15 at 08:39

1 Answers1

1

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

Tim Norris
  • 256
  • 2
  • 10