监视后面的ASP.NET代码

时间:2015-07-01 08:57:46

标签: asp.net webforms

假设我有一个简单的代码隐藏文件:

public partial class Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        MyClass instance = new MyClass();
        instance.MyMethod();
    }

    protected override void OnUnload(EventArgs e)
    {
        base.OnUnload(e);
        var trace = Environment.StackTrace;
        Debug.WriteLine(trace);
    }
}

这是输出(我已经缩短了一点):

   at System.Environment.GetStackTrace(Exception e, Boolean needFileInfo)
   at System.Environment.get_StackTrace()
   at WebTesting.Default.OnUnload(EventArgs e) in d:\Projects\07\WebTesting\WebTesting\Default.aspx.cs:line 28
   at System.Web.UI.Control.UnloadRecursive(Boolean dispose)
   at System.Web.UI.Page.UnloadRecursive(Boolean dispose)
   at System.Web.UI.Page.ProcessRequestCleanup()
   at System.Web.UI.Page.ProcessRequest(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
   at System.Web.UI.Page.ProcessRequest()
   at System.Web.UI.Page.ProcessRequestWithNoAssert(HttpContext context)
   at System.Web.UI.Page.ProcessRequest(HttpContext context)
   at ASP.default_aspx.ProcessRequest(HttpContext context) in c:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\vs\8bc80b93\42174b23\App_Web_ut1iqnjz.0.cs:line 0

正如您所看到的,输出不包含对Myclass.MyMethod()的任何调用。问题是:我如何追踪方法?我需要的是在页面执行期间发生的每个方法调用的跟踪。有可能吗?

0 个答案:

没有答案