Application_Start not being hit in ASP.NET web app

I’m trying to debug something in the global.asax.cs file in an ASP.NET web app and have set a breakpoint in the Application_Start() event however that event is not getting fired when I start the web app inside VS2008. I’m targeting the 3.5 framework.

What could prevent this event from being fired? Or how could I have messed up the project such that this event is no longer wired up?

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

One easy trick to debug newly written code in the global.asax file is to save the web.config file. Each time the config.file is saved, the application is stopped and started.

You could find useful information in this blog entry

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

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…

One of the proposed workarounds:

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

alt text

(from the Visual Web Developer Team Blog)

Method 2

If i remember correctly, Application_Start runs before the debugger can hook up to the application.

Try doing something else to check if the Application_Start method runs, like setting an application variable:

Application("app") = "started"

Then display the application variable in the page to see if it was set.


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x