How to debug the ASP.Net application shutdown code (Application_End
application event)
By George Mihaescu
Summary: This article is a quick tip, describing a
simple way to debug the code executed when an ASP.Net application is shut down,
such as the Application_End event handler. The tip works only in .Net
2.0.
The problem: You have code executed when the
application is shut down (such you’ve handled the Application_End event
in Global.asax). You want to be able to set a breakpoint in that code
and hit it.
The solution: The simplest solution I’ve found relies
on the fact that starting with ASP.Net 2.0 the app domain is recycled when a
subdirectory of the web application is renamed. Therefore:
- set the breakpoint you need in the application shutdown
code
- start debugging in VS 2005
- in Windows explorer rename a subdirectory of the Web
application (if you don’t have one, create one first). As a consequence of
the subdirectory being renamed, the application domain will be recycled by
the ASP.Net worker process and your breakpoint will be hit