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
我记得在Scott Gu的Razor公告中提到完全调试器对Razor视图的支持;我已经意识到能够在Razor视图中设置断点,还会遇到无法在视图中设置断点,只是很快意识到它是一个ASPX视图。 :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?
有时我无法帮助/改变现有视图使用ASPX视图引擎:有没有一种方法我还没学会在ASPX视图中设置断点?如果没有,那么下一个最好的东西是什么?是否有比Debugger.Break()更好的解决方法并在调试后恢复?
1 个解决方案
#1
11
Contrary to popular belief you can actually set breakpoints in ASPX views.
与流行的看法相反,您实际上可以在ASPX视图中设置断点。
In Visual Studio you can navigate your cursor at the desired location, hit F9 (Toggle Breakpoint) and it's done.
在Visual Studio中,您可以将光标导航到所需位置,按F9(切换断点)并完成。
It can be done in Razor and ASPX views, and even in ASPX pages (in WebForms).
它可以在Razor和ASPX视图中完成,甚至可以在ASPX页面中(在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 @...
).
如果你不能在那里设置断点,那意味着给定的部分不是C#代码而是HTML部分。你不能在之类的部分设置断点,你只能在愚蠢的<%和%>部分之间设置断点(在Razor中它是@ {...},@(...)或者只是@ .. )。
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).
还要确保您的应用程序已构建,并且调试器已附加到服务器实例(如果它在IIS Express上,则在项目属性中切换到Development Server,反之亦然)。
Stop the development server instances on the taskbar, rebuild your project and start it again. It should hit the breakpoint just fine.
停止任务栏上的开发服务器实例,重建项目并再次启动它。应该打破断点就好了。
#1
11
Contrary to popular belief you can actually set breakpoints in ASPX views.
与流行的看法相反,您实际上可以在ASPX视图中设置断点。
In Visual Studio you can navigate your cursor at the desired location, hit F9 (Toggle Breakpoint) and it's done.
在Visual Studio中,您可以将光标导航到所需位置,按F9(切换断点)并完成。
It can be done in Razor and ASPX views, and even in ASPX pages (in WebForms).
它可以在Razor和ASPX视图中完成,甚至可以在ASPX页面中(在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 @...
).
如果你不能在那里设置断点,那意味着给定的部分不是C#代码而是HTML部分。你不能在之类的部分设置断点,你只能在愚蠢的<%和%>部分之间设置断点(在Razor中它是@ {...},@(...)或者只是@ .. )。
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).
还要确保您的应用程序已构建,并且调试器已附加到服务器实例(如果它在IIS Express上,则在项目属性中切换到Development Server,反之亦然)。
Stop the development server instances on the taskbar, rebuild your project and start it again. It should hit the breakpoint just fine.
停止任务栏上的开发服务器实例,重建项目并再次启动它。应该打破断点就好了。