Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't break in global.asax / Application_Start

I got a break point on the first line of Application_Start(), but Visual Studio wont break on it.

Visual Studio have attached itself to the IIS working process:

Auto-attach to process '[2092] w3wp.exe' on machine 'SRD00510' succeeded.

My breakpoint in the home controller do work.

update

I've tried:

  • iisreset
  • restarted visual studio
  • Rebooted.
  • Tried to reinstall aspnet (aspnet_regiis -i)
like image 353
jgauffin Avatar asked May 30 '12 13:05

jgauffin


People also ask

What is Application_Start in global asax?

Application_Start. The Application_Start event is fired the first time when an application starts. Session_Start. The Session_Start event is fired the first time when a user's session is started. This typically contains for session initialization logic code.

How do I use global asax?

How to add global. asax file: Select Website >>Add New Item (or Project >> Add New Item if you're using the Visual Studio web project model) and choose the Global Application Class template. After you have added the global.

Can we delete global asax?

asax file. Can I delete it? YES BUT you shouldn't.


1 Answers

Reading your question, I assume you are using IIS for debugging, not Visual Studio Development Server.

In this case, debugging application start is tricky, because it is only called once when the application pool is started or recycled. When Visual Studio attaches to the process, Application_Start has already been running.

The trick is to make the application pool recycle without killing the process you are attached to.

Do the following:

  1. In Visual Studio (must be run as Administrator) set your breakpoint in global.asax.cs and start debugging as usual (F5). The page opens in your web browser, but the breakpoint isn't hit.
  2. Now the trick: With a text editor, open web.config from where it is served by IIS, change it (e.g. enter a blank line somewhere) and save it. In contrast to recycling the application pool in IIS, this lets the application pool recycle (and thus running through Application_Start in global.asax.cs the next time the web site is called) without killing the process you are attached to.
  3. In your web browser, reload the page. The breakpoint should be hit now!

That works for me (IIS 7.5, VS2015).

like image 134
Jochen Avatar answered Oct 24 '22 02:10

Jochen