Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Application_End() WebApi

In ASP.NET WebAPI there is a method called ApplicationStart in the global.asax.cs file which is automagically called when the application started. How is this called?

The reason I ask is I would like to add an Application_End method to do any cleanup I need to do.

like image 430
deanvmc Avatar asked Dec 21 '12 15:12

deanvmc


1 Answers

ASP.NET WebApi is no different than ASP.NET when it comes to the Global.asax methods. These methods are discovered via reflection by the IIS application pool worker when the application is loaded and are then invoked at the appropriate times. There is a nice overview of this on MSDN.

Application_Start() is called by IIS when the application starts running inside the application pool. Generally, this happens when a request comes in for a resource within the application's domain. After all, the application has to be running for the request to be serviced.

Application_End() is called just before the application is unloaded or just before the application pool recycles. There are various triggers that cause the application pool to recycle.

like image 58
Fls'Zen Avatar answered Jan 02 '23 21:01

Fls'Zen