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, particularly the Global.asax methods like Application_Start()
and Application_End()
.
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.