I have a webservice where I want to do something when a the application pool ends, so I thought I’d do:
Application_End()
{
// Some logic here
}
What happens is if I stop the application pool, this logic is executed.
On the other hand, if I just call iisreset, it is NOT.
So my question is: where should I put my code so that it is executed in both cases?
There is no guarantee that Application_End will be called. The example you mentioned, where you perform an IIS reset is an example. Other examples could include someone unplugging the server, or a hardware failure.
What I’ve done in the past is to use Application_Start to call my data cleanup logic as the application comes back online. This is assuming you don’t need any values that were stored in memory.