Thông tin tài liệu:
Dan Wahlin khả năng gỡ lỗi mã là một kỹ năng mà mỗi nhà phát triển cần phải có trong kho vũ khí của họ bất kể của công nghệ mà họ đang sử dụng. Nó đi mà không nói rằng sự hiểu biết tùy chọn gỡ lỗi khác nhau mà có sẵn có thể tiết kiệm một lượng lớn thời gian trong một dự án và có lẽ ngay cả một vài đau đầu. Trong khi nhiều nhà phát triển quen với việc sử dụng Visual Studio. NET Web Developer Express để gỡ lỗi các ứng dụng ASP.NET sử...
Nội dung trích xuất từ tài liệu:
Debugging ASP.NET AJAX ApplicationsDebugging ASP.NET AJAX ApplicationsDan WahlinThe ability to debug code is a skill that every developer should have in their arsenal regardless of the technology they’re using. It goes without saying that understanding the different debugging options that are available can save a tremendous amount of time on a project and perhaps even a few headaches. While many developers are accustomed to using Visual Studio .NET or Web Developer Express to debug ASP.NET applications that use VB.NET or C# code, some aren’t aware that it’s also extremely useful for debugging client-side code such as JavaScript. The same type of techniques used to debug .NET applications can also be applied to AJAX -enabled applications and more specifically ASP.NET AJAX applications.In this article you’ll see how Visual Studio 2008 Beta 2 and several other tools can be used to debug ASP.NET AJAX applications to quickly locate bugs and other issues. This discussion will include information about enabling Internet Explorer 6 or higher for debugging, using Visual Studio 2008 and the Script Explorer to step through code as well as using other free tools such as Web Development Helper. You’ll also learn how to debug ASP.NET AJAX applications in Firefox using an extension named Firebug which lets you step through JavaScript code directly in the browser without any other tools. Finally, you’ll be introduced to classes in the ASP.NET AJAX Library that can help with various debugging tasks such as tracing and code assertion statements.Before you try to debug pages viewed in Internet Explorer there are a few basic steps you’ll need to perform to enable it for debugging. Let’s take a look at some basic setup requirements that need to be performed to get started.Configuring Internet Explorer for DebuggingMost people aren’t interested in seeing JavaScript issues encountered on a Website viewed with Internet Explorer. In fact, the average user wouldn’t even know what to do if they saw an error message. As a result, debugging options are turned of f by default in the browser. However, it’s very straightforward to turn debugging on and put it to use as you develop new AJAX applications.To enable debugging functionality, go to Tools Internet Options on the Internet Explorer menu and select the Advanced tab. Within the Browsing section ensure that the following items are unchecked: Disable script debugging (Internet Explorer) Disable script debugging (Other)Although not required, if you’re trying to debug an application you’ll probably want any Ja vaScript errors in the page to be immediately visible and obvious. You can force all errors to be shown with a message box by checking the Display a notification about every script error checkbox. While this is a great option to turn on while you’re developing an application, it can quickly become annoying if you’re just perusing other Websites since your chances of encountering JavaScript errors are pretty good.Figure 1 shows what the Internet Explorer advanced dialog should look after it has been properly configured for debugging. Figure 1. Configuring Internet Explorer for debugging.Once debugging has been turned on, you’ll see a new menu item appear in the View menu named Script Debugger. It has two options available including Open and Break at Next Statement. When Open is selected you’ll be prompted to debug the page in Visual Studio 2008 Beta 2 (note that Visual Web Developer Express can also be used for debugging). If Visual Studio .NET is currently running you can choose to use that instance or to create a new instance. When Break at Next Statement is selected you’ll be prompted to debug the page when JavaScript code is executed. If JavaScript code executes in the onLoad event of the page you can refresh the page to trigger a debug session. If JavaScript code is run after a button is clicked then the debugger will run immediately after the button is clicked.Note: if you are running on Windows Vista with User Access Control (UAC) enabled, and you have Visual Studio 2008 set to run as an administrator, Visual Studio will fail to attach to the process when you are prompted to attach. To work around this issue, start Visual Studio first, and use that instance to debug.Although the next section will demonstrate how to debug an ASP.NET AJAX page directly from within Visual Studio 2008, using the Internet Explorer Script Debugger option is useful when a page is already open and you’d like to more fully inspect it.Debugging with Visual Studio 2008 Beta 2Visual Studio 2008 Beta 2 provides debugging functionality that developers around the world rely on everyday to debug .NET applications. The built-in debugger allows you to ...