6

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?

4
  • 1
    stackoverflow.com/questions/1354764/… Commented Apr 15, 2013 at 6:45
  • Thanks, @Freelancer. I reviewed that question before posting mine, but I think it is a bit different. Commented Apr 15, 2013 at 6:48
  • 1
    Can't you just F9 at the given location? I remember using breakpoints in my aspx views back in the day. Commented Apr 15, 2013 at 7:00
  • i always put breakpoint in the controller that is returning to the view where i want to break. the controller takes me to the view and there i can step into the razor syntax. Commented Apr 17, 2013 at 10:20

1 Answer 1

11

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Excellent - so glad I asked! This is a case of self-fulfilling prophecy: in my experience, many think this is only possible with Razor (as if the Razor announcement highlighted full debugger support in contrast to ASPX's complete lack thereof)...and quickly find "supporting" evidence; I started down the same path but remained skeptical. Rechecking the view in question this time, a bit of markup on the same line as <% snagged clicking to set a breakpoint, yielding "This is not a valid location for a breakpoint." Clicking to put the cursor after <% then pressing F9 worked, though.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.