Every .NET developer should know how to set breakpoints in Visual Studio 2012.
- Right-click a line in your code, then select Breakpoint -> Insert Breakpoint.
- Or, simply press F9 after placing your cursor on the line of code.
But, what if that line of code is in your Global.asax code? Will the breakpoint still work when you run the application? If not, what can you do to get it to work?
Try the following steps:
- Create a new web project in Visual Studio (or open an existing web project).
- Open the file Global.asax.cs from your application’s root folder.
- Set a breakpoint in your Application_Start method.
- Run the application in your browser by pressing F5.
The breakpoint will most likely be skipped, because the code has already executed in IIS by the time the debugger is attached. Fortunately, there is an easy way to resolve this.
Here are some additional steps:
- Open the Global.asax markup file in the code editor. (See Help section below if you’re not sure how to do this.)
- Make an inconsequential change in it (e.g. add a space inside the closing > tag.
- Refresh the application in your browser.
Results:
You should now see that the breakpoint has been hit after running the application!
Need Help?
If you weren’t sure how to open the Global.asax markup file, try the following.
- Right-click the Global.asax file in Solution Explorer.
- Select View Markup from the popup context menu.
Pingback: Hitting Breakpoints in Global.asax using Visual Studio | Senior DBA
In the web there are a lot of solutions for this problem but this is the only that really works! Moreover it’s also the simplest! Thank you!!!!
work great
You’re a genius!