2

I'm debugging a project website with several classes; while most of the code is handled in C#, are several if statements in the HTML-based pages, which uses sessions to update itself.

So, for example, I press a button, and the HTML-based page calls out a Javascript function, which then calls out a C# function.

<input class='buttonbrowse' type="button" name="btnShiftDate" value="..." <%=(requestApplicationForm.Paycode==null ? " disabled=disabled" : "")%> onclick="javascript:SelectExcessHrs_time();" id="Button1" />

This function does a lot of calculation, and stores all the variables and whatnot in a class 'paycodeform'.

At the end of the code, this is returned:

Session["SubsidyApplicationForm"] = paycodeform;

Back in the HTML Page, this happens:

<%if(requestApplicationForm.Excessdatepunch!=null) {%>

Etc., etc. Basically, there are in-line C# codes (is that what one would call them?) embedded in the HTML page. A LOT of codes. And they do some sort of filtering through the paycodeform.

Excessdatepunch is an array, which contains values at the time paycodeform was passed back into the session. Unfortunately, somewhere along the HTML code, the Excessdatepunch array is cleared, and re-supplied with default values - running through the long list of codes is frustrating, and to complicate matters further, this error doesn't happen often.

So as with the title, I'd like to ask if there's someway to monitor these in-line C# codes. I know that placing a breakpoint there won't work, while placing a watch on the session doesn't exactly give me the inner workings such as the values inside the Excessdatepunch array.

4

1 回答 1

1

可以使用System.Diagnostics.Debugger.Break(). 您还可以写入跟踪和调试侦听器。尝试调试以下代码示例:

<form id="form1" runat="server">
    <div>
        This is some HTML. The current time is:
        <%
            System.Diagnostics.Debugger.Break();
            Session["CurrentTime"] = DateTime.Now;
        %>
    </div>
    <%
        System.Diagnostics.Trace.WriteLine(Session["CurrentTime"]);
        System.Diagnostics.Debug.WriteLine(Session["CurrentTime"]);
        System.Diagnostics.Debugger.Break();
        Response.Write(Session["CurrentTime"]);
        Response.Write("<br/>");
    %>
    You should see the current date above this line.
</form>

如果要在页面中显示跟踪输出,请将Trace属性添加到<%@ Page %>标记:

<%@ Page Language="C#" Trace="true" ... %>

参考:

于 2013-07-04T07:18:59.987 回答