global.asax breakpoint not hit

user259286 picture user259286 · Oct 5, 2011 · Viewed 17.5k times · Source

I have some code in my ASP.NET app in C# that's in the Global.asax.cs code file. In the Application_Start, Session_Start and Application_Begin Request I have set some breakpoints. However none of these are ever hit. I'm working on my local machine with VS8.

Here's what I've tried:

  • Stopped the ASP Dev Server
  • Deleted all ASP.NET Temporary files
  • Created new Global.asax
  • Closing VS and opening back up
  • Clean and Rebuild project

Upon trying my after these, the breakpoints will not hit.

Any ideas why this might be?

Answer

Jeff Reddy picture Jeff Reddy · Mar 12, 2012

I've run into this same problem. I'm assuming you are using your local IIS instead of the VS Development Server. If this is the case, you won't be able to debug/Step through this code in the Global.asax.cs file because by the time the debugger has attached, this code has already executed in IIS. However, if you use the Dev server, you have the ability to get to this code as the debugger will already be attached.

So, Change the server in your project properties to use the Visual Studio Development Server.

This can be found by right clicking your project within Visual Studio > Project Properties > Web tab > Use Visual Studio Development Server.