下面是在不同的方式来debug AJAX-enabled ASP.NET application

(1)在Configuration文件中授权.
(2)在服务端使用tracing
(3)使用在Sys.Debug类的方法设置breakpoints和handle trace输出
(4)在浏览器材里面授权debugging
(5)追加Visual Studio2008 debugger或在你的浏览器里面扩展工具.
(7)使用扩展工具捕获HTTP的交换.


(1)在Configuration文件中授权.


在Configuration中添加一个compilation元素,设置一贯debug属性为"true",如下面:

Debugging and Tracing AJAx Applications<configuration>
Debugging and Tracing AJAx Applications  
<system.web>
Debugging and Tracing AJAx Applications    
<compilation debug="true">
Debugging and Tracing AJAx Applications      
<!-- etc. -->
Debugging and Tracing AJAx Applications    
</compilation>
Debugging and Tracing AJAx Applications  
</system.web>
Debugging and Tracing AJAx Applications
<configuration>


要将应用程序发布,就要从debug该为Release才能发布

在Web.config文件中,如果compilation元素中包括debug,就将里面debug属性该为"false"

确定在ScriptManager中面的ScriptMode属性设置为Release

而在@page中指定的debug属性不会影响ASP.NET AJAX applications.而为ScriptManager在Web.config中设置的IsDebuggingEnabled and ScriptMode属性是决定是否呈现debug脚本.


(2)Tracing on the Server


怎样授权ASP.NET页面Tracing就是这样
<%@ Page Trace="true" %>

而在ASP.NET AJAX中就必须有一个partial-page呈现授权,也就是要在ScriptManager中将EnablePartialRendering属性设置为"true",
其实就是所说的饿"view debugger trace messages in the Output window".

(3)Debug Helper Class

ASP.NET为调试客户端应用程序提供一个Sys.Debug Class.如果你是IE你可以在你的也面上创建一个


就是使用下面的方法:

Sys.Debug.assert(condition,message,displayCaller)
给出检测条件,并如果条件为false时候,就会有在debugger中提示.

Sys.Debug.clearTrace()
清楚所有的指定在id为"TraceConsole"元素中显示的信息.

Sys.Debug.traceDump(object,name)

抑制一个对象在debugger console和TraceConsole中输出.

Sys.Debug.fail(message)
显示一个message在debugger的输出窗口和TraceConsole的textarea元素中

Sys.Debug.trace(text)
在debugger console和TraceConsole中追加一行文本.
这个是MSDN上的事例
Debugging and Tracing AJAx Applications<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
Debugging and Tracing AJAx Applications
<html >
Debugging and Tracing AJAx Applications
<head id="Head1" runat="server">
Debugging and Tracing AJAx Applications    
<title>Untitled Page</title>


(4)To enable debugging in Internet Explorer

就是在IE里面设置Disable Script Debugging.
Disable Script Debugging (Other)
Display a notification about every script error
Show friendly HTTP error messages
都打开就能调试js.

当然还可以使用我们熟悉的那IE的扩展工具.

Attaching the Visual Studio Debugger to Internet Explorer

你要debug客户端的脚本,你必须追加debugger到IE里面.

在Visual Studio debugger中选中Debug menu,选中Attach to Process,只后会有一个Attach to Process对话框.选种iexplore.exe.

这样就可以拉.如果你使用IE遭遇脚本错误,并且你按这样的设定,但不在当前就追加到debugger中,浏览器会提示你选择一个debugger.你既能继续不debugging或追加一个debugger直接通过代码.


相关文章: