When IIS restarts an ASP.Net (2.0) web application, it can either:
- Recycle the AppDomain: Unload the AppDomain and load a new AppDomain on the same process (e.g. when
HttpRuntime.UnloadAppDomain()
is called, when web.config is changed). - Recycle the process: unload the AppDomain and load a new one on a new process (e.g. when invoking Recycle command on an AppPool via inetmgr, or when memory limit is reached).
Due to some internal reasons (trouble with legacy native code we depend upon), we cannot allow the first option. We just can't load the application twice on the same process.
Can IIS be somehow told to never allow worker process reuse?
I've tried preventing it myself by tracking whether an application has already started on a process once using a Mutex, and if so - throwing an exception during Application_Start()
); I've also tried terminating the process by calling Environment.Exit()
during Application_End()
. The problem with both methods is that it causes any requests that arrive during Application_End or Application_Start to fail (unlike a manual process recycle, which fails absolutely no requests because they are redirected to the new process right away).