Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting Breakpoints in MVC ASPX Views

I recall in Scott Gu's Razor announcement mention of full debugger support for Razor views; and I have appreciated being able to set breakpoints in Razor views, also bumped into not being able to set a breakpoint in a view, only to realize quickly that it is an ASPX view. :P

Sometimes I cannot help/change that an existing view uses the ASPX view engine, though: is there a way I've yet to learn to set breakpoints in an ASPX view? If not, what is the next best thing? Is there a better workaround than Debugger.Break() and reverting after debugging?

like image 460
J0e3gan Avatar asked Apr 15 '13 06:04

J0e3gan


1 Answers

Contrary to popular belief you can actually set breakpoints in ASPX views.

In Visual Studio you can navigate your cursor at the desired location, hit F9 (Toggle Breakpoint) and it's done.

It can be done in Razor and ASPX views, and even in ASPX pages (in WebForms).

If you CAN'T set the breakpoint there that means that the given part is not C# code but the HTML part instead. You can't set breakpoints at parts like <span>, you can only set it between the silly <% and %> parts (in Razor it is @{...}, @(...) or simply @...).

Also make sure your application is built, and the debugger is attached to the server instance (if it's on IIS express switch to Development Server in the project properties, and vica-versa).

Stop the development server instances on the taskbar, rebuild your project and start it again. It should hit the breakpoint just fine.

like image 77
vinczemarton Avatar answered Sep 17 '22 22:09

vinczemarton