Workaround: Debugging Global.aspx.cs Application_Start() with ASP.Net Web Server within Visual Studio

Web Development Tools Microsoft

When you add a global.asax file to your “Web Application Projects (WAPs) like below:

image

and then write code in Application_Start event and try to debug it like below using Visual Studio inbuilt Development Web Server

image 

Then during your first debug the breakpoint is hit but during your subsequent debug runs the breakpoint is not hit.

The reason behind this is that we do not kill the ASP.Net Web Server process after your every debug run and hence Application_Start() is not fired every time.  There is a good reason why we do so…  Starting ASP.Net Web Server process is an expensive task and in most of the scenarios recycling this process after every debug would adversely impact your performance…  If you do not want to debug your Application_Start() method then probably you do not need to have the process restart and save performance most of the time… 

However if you would like to have the breakpoint hit you have few easy workarounds… One of the workaround is that you stop the web server from your system tray as in the figure below:

image

Alternatively you can go to your property pages of your web application and enable Edit & Continue like shown below:

image

When you choose Edit and Continue then we recycle the ASP.Net Web Server process on every debug run (it is needed for the Edit & Continue functionality to work)…  This way although you will see very marginal degrade in your performance you will still be able to debug your Application_Start() methods…

Hope this helps…

– Vishal R. Joshi | Program Manager | Visual Web Developer Team

0 comments

Discussion is closed.

Feedback usabilla icon