• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
works guo

成功的渴望与生俱来---- 成功是获得赞美与尊重的最有效的途径
博客园    首页    新随笔    联系   管理    订阅  订阅

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">
      
<!-- etc. -->
    
</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就是这样
<%@ 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上的事例
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html >
<head id="Head1" runat="server">
    
<title>Untitled Page</title>
<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");
    alert(
"Hello " + form1.text1.value + ".");
}


function btnClear_onclick() {
    Sys.Debug.clearTrace()
    alert(
"Trace console cleared.");
}

</script>
</head>
<body>
<form id="form1" runat="server">
    
<h2>Sys.Debug Methods Test Page</h2>
    
<asp:ScriptManager ID="ScriptManager1" 
        runat
="server" />
    
<p><b>Use these buttons to demonstrate the assert() and fail() 
    methods:
</b><br />
    
<input id="btnAssert" type="button" value="Assert" 
        style
="width: 100px" 
        onclick
="return btnAssert_onclick()" /> &nbsp
    
<input id="btnFail" type="button" value="Fail" 
        style
="width: 100px" onclick="return btnFail_onclick()" />
    
</p><hr />
    
<b>Use the textbox and buttons below to demonstrate tracing.</b>
    
<br />
    
<p>Enter your name here:<br />
    
<input id="text1" maxlength="50" type="text" />
    
<br />
    
<br />
    
<input id="btnTrace" type="button" value="Trace" 
        style
="width: 100px" onclick="return btnTrace_onclick()" /><br />
    
<input id="btnDump" type="button" value="TraceDump" 
        style
="width: 100px" onclick="return btnDump_onclick()" /><br />
    
<input id="btnClear" type="button" value="ClearTrace" 
        style
="width: 100px" onclick="return btnClear_onclick()" /><br />
    
<br /></p>
    View output in the TraceConsole textarea below.
    
<br />
    
<textarea id='TraceConsole' rows="10" cols="50" 
        title
="TraceConsole"></textarea>
</form>
</body>
</html>


(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直接通过代码.


posted @ 2008-03-09 16:01  works guo  阅读(461)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3