Debugging Web Projects with Visual Studio .NET


Visual Studio .NET offers an integrated environment for developing and debugging of ASP .NET applications. All you need to do to debug an application is add breakpoints to your code and run the application.

As you run the application, if the debugger encounters a line of code with a breakpoint, it pauses the execution of the program and puts you back in the edit window. From there you can step through the code one line at a time and analyze variables .

To debug a Web application using VS .NET:

  1. Select a file that contains code you wish to debug. To do so, click View > Solution Explorer.

  2. Right-click on the file and select View Code from the pop-up menu.

  3. Place the cursor on the line of code you wish to stop.

  4. Press F9 or right-click on the line of code and select Insert breakpoint from the pop-up menu. The line will be highlighted in red ( Figure 1.15 ).

    Figure 1.15. VS .NET highlights in red code that has a breakpoint, though it's hard to tell from this grayscale figure (they appear as reversed characters in the figure).

    graphics/01fig15.jpg

  5. Choose Debug > Start from the top menu.

graphics/tick.gif Tips

  • Once you run the program in the debugger, do something that will trigger the code where you put a breakpoint. If it is the code for the button, click the button. This will cause the debugger to halt at the breakpoint and put you back in the editor window with the line highlighted in yellow ( Figure 1.16 ).

    Figure 1.16. When the debugger reaches a line with a breakpoint, it pauses the program and puts you back to the code editor window. The line of code highlighted in yellow on your screen is the next line the debugger will execute.

    graphics/01fig16.gif

  • Once you stop at a breakpoint, Press F11 to execute one line at a time.

  • When you hit a breakpoint you can edit your code, but the changes won't take effect immediately. You have to restart the debugger for the changes to kick in.

  • The Locals window within the development window (or in fancy terms, IDE for Interactive Development Environment) displays the variables available in the function that is currently executing.

  • The Command Window lets you read or set the value of a variable. Type ? varname to print the value of a variable or varname = value to set the value of a variable, then press Enter.

  • Even while the debugger is running, you can go back to the IDE, find a line of code, and place a breakpoint. The debugger will stop at that line without your having to restart the application.

  • Choose Debug > Stop Debugging to stop the debugger.

  • Press Ctrl-F5 to run the Web application without the debugger. This is useful when you want to run the program without stopping at each breakpoint and without first having to remove all the breakpoints.




C#
C# & VB.NET Conversion Pocket Reference
ISBN: 0596003196
EAN: 2147483647
Year: 2003
Pages: 198
Authors: Jose Mojica

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net