简体   繁体   English

如何调试服务器端JScript代码

[英]How to debug server-side JScript code

I need to maintain a classic ASP project which requires debugging server-side JScript code. 我需要维护一个经典的ASP项目,该项目需要调试服务器端JScript代码。 For example, consider an A.aspx file with the following code: 例如,考虑具有以下代码的A.aspx文件:

<% @Page Language="JScript" aspcompat="true" %>
<%
var a = 1;
var b = a + a;
...// Other statements here
Response.Write(b);
%>

In Visual Studio, I cannot put any breakpoint on any server-side jscript lines or blocks, eg put a breakpoint on line var b = a + a; 在Visual Studio中,我不能在任何服务器端jscript行或块上放置任何断点,例如,在var b = a + a;行上放置断点var b = a + a;

However, it's okay for client-side javascript code debugging. 但是,客户端javascript代码调试也可以。 It becomes a big pain for me to debug code like this. 调试这样的代码对我来说是一个很大的痛苦。

I want to know how to debug server-side jscript code or if any tools support such features? 我想知道如何调试服务器端jscript代码,或者是否有任何工具支持此类功能?

Thanks. 谢谢。

I saw this online but I haven't tried before. 我在网上看到了此内容,但之前从未尝试过。

So far I try to debug in writing it on the scree by 到目前为止,我尝试通过以下方式在屏幕上进行调试:

<%@ LANGUAGE="JavaScript" %>
<%
var blnTrace;
var strTrace = Application("g_Trace");
if (strTrace && strTrace.toUpperCase() == "TRUE")
    blnTrace = true;
else
    blnTrace = false;

var a = 1;
var b = a + a;
...// Other statements here

if (blnTrace)
{
    Response.Write(b);
}

...// Other statements here

%> %>

So that I can turn on/off the debug message. 这样我就可以打开/关闭调试消息。

I ran into this same issue recently while working on an old website. 我最近在一个旧网站上工作时也遇到了同样的问题。

You can cause the application to break by calling Debugger.Break . 您可以通过调用Debugger.Break导致应用程序中断。

Press F5 to debug the website, when the application hits that line of code it will behave the same as if there is a breakpoint there. F5调试网站,当应用程序点击该行代码时,它的行为将与那里的断点相同。

Make sure to remove this before you move to a production enviroment or set Debug="false" 在移至生产环境或设置Debug="false"之前,请确保将其删除。

<% @Page Language="JScript" aspcompat="true" %>
<%
var a = 1;
System.Diagnostics.Debugger.Break();
var b = a + a;
...// Other statements here
Response.Write(b);
%>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM