作业帮 > ASP.NET > 教育资讯

ASP.NET教程:在ASP.NETAjax里使用跟踪

来源:学生作业帮助网 编辑:作业帮 时间:2024/05/14 05:51:09 ASP.NET
ASP.NET教程:在ASP.NETAjax里使用跟踪
ASP.NET教程:在ASP.NETAjax里使用跟踪ASP.NET
【51Test.NET-ASP.NET教程:在ASP.NETAjax里使用跟踪】:
如果你在使用ASP.NET Ajax的时候,遇到一个页面问题,想在调试时候跟踪语句,有个比较快速的方法:使用“Sys.Debug.trace函数。

为了看到跟踪输出的内容,在页面上加一个TextArea的控件,控件的ID为“TraceConsole。这个现实的跟踪的可用性,一旦应用,将意味着将该TextArea必须手动添加到输出。不过,在调试网站的时候,跟踪的内容也被写到Visual Studio的输出窗口,就像FireFox的输出控制台一样。

Sys.Debug 类还有其他许多好的方法,例如:

assert:如果被测试的条件是false的,将会有个消息框来显示消息。

fail:引发程序终止或中断调试。

traceDump:用清晰的格式显示对象数据。

延伸阅读:

1、有关Sys.Debug 参见:http://msdn.microsoft/zh-cn/library/bb397422.aspx

2、Debugging and Tracing AJAx Applications

下面是在不同的方式来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如下面:

configuration

system.web

compilation debug=true

compilation

system.web

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就是这样

而在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上的事例

DOCTYPE html PUBLIC -//W3C//DTD XHTML 1.1//EN http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd

html

head id=Head1 runat=server

titleUntitled Pagetitle

script language=javascript type=text/javascript

function btnAssert_onclick() {

var n;

// Insert code intended to set n to a positive integer.

if (false) n = 3;

// Assert if n is not greater than 0.

Sys.Debug.assert(n 0, n must be set to a positive integer.);

}

function btnFail_onclick() {

var n;

// Insert code intended to set n to a numeric value.

if (false) n = 3;

// Fail if n is not numeric.

if (isNaN(n)) Sys.Debug.fail(The value of n must be a number.);

}

function btnTrace_onclick() {

v = form1.text1.value;

Sys.Debug.trace(Name set to + “ + v + “.);

alert(Hello + v + .);

}

function btnDump_onclick() {

Sys.Debug.traceDump(form1.text1, Name textbox);

ASP.NET