In Java, we can implement and configure an interface that listens when the application is being deployed and undeployed through ServletContextListener
. For example, I can execute some tasks to load data in global cache at deploy time and execute temporary files removal tasks when the application is undeployed (these are just examples, doesn't mean I will do some of them in my app).
Is there an equivalent class/interface in asp.net applications? Or how can I achieve this behavior?
I would want to perform some tasks when the web application is being undeployed (stopped) rather than when it is deployed (started).
It looks like ServletContextListener notifies when a servlet is added to or removed from a context. ASP.NET applications are not servlets, and are not loaded into a context, so there's no complete equivalent.
There are Application* events, however. Create an ASP.NET web application and look in Global.asax.cs:
ServletContext#contextInitialized
equivalent is Application_Start
method.ServletContextListener#contextDestroyed
equivalent is Application_End
method.More info: