When IIS restarts an ASP.Net (2.0) web application, it can either:
HttpRuntime.UnloadAppDomain()
is called, when web.config is changed).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).
Couldn't find a way to tell IIS that worker processes are not to be reused. Can't afford fixing the underlying problem that forbids process reuse. Therefore, ended up calling Environment.Exit(0)
in Application_End
, although it may cause a small number of requests to fail with a connection reset.