Why does not the Application_Start() event fire when I debug my ASP.NET MVC app?

I found the following answer on forums.asp.net:

Are you using IIS7 as the server or the built-in web server? I noticed when using IIS7 that if you start the debugger, let a page come up, then change Global.asax (the markup file, not code-behind) while the debugger is still running, then refresh the page, breakpoints in Application_Start will be hit.

I think what's happening is that pressing "play", VS just fires up the process, then attaches to it, but by the time it attaches to it the start event has already run. By changing Global.asax, you cause the app to restart and since the debugger's already attached you can hit the breakpoint. Not a great solution, but it seems to work.

Thats's what was happening in my case.


Add a System.Diagnostics.Debugger.Break(); to Application_Start().
This will force a breakpoint.

This line should be commented out to avoid the breakpoint to happen and #ifdef debug to get sure never gets to production.

NOTE: this is a problem with IIS. Since I wrote this answer, things have changed, and you can avoid doing this by using other servers, like IIS Express.


I believe you have to shutdown/stop the local debugging server in order for the Application_Start() event to fire again... you should be able to right click on it in the system tray and choose "Stop".