asp.netvisual-studio-2010debuggingapplication-end

How to exit an ASP.NET application gracefully when stopping debugging in VS 2010?


I develop and debug an ASP.NET application with VS 2010. My ASP.NET application holds some connections to other applications on other machines. When I stop debugging, I want these connections to be released. If this doesn't happen, these other applications fail and I have to restart them.

In the end I will store my termination code in the Application_End method in Global.asax.cs, but this one is not called when stopping debugging.

Is there a way to terminate the debugging of my ASP.NET application so that not everything is killed at once, but so that one last method is called in which I could add my termination code?


Solution

  • I misunderstood how debugging an ASP.NET application works. I thought the moment I stop debugging (by pressing Shift+F5) the ASP.NET application is terminated and no further line of code is executed. It was my explanation to why the Application_End method is not called.

    But in fact the ASP.NET application goes on when the debugger is detached and therefore the Application_End method is not called.