为什么跟踪在ASP.NET MVC子操作中不起作用?

时间:2011-05-03 14:49:24

标签: asp.net-mvc asp.net-mvc-3

在ASP.NET MVC 3应用程序中,从父Controller方法(或从它调用的业务对象)调用HttpContext.Trace.Write和System.Diagnostics.Trace.Write会导致Trace.axd中的条目。 / p>

如果父视图调用子操作,例如Html.RenderAction(“ChildAction”)然后,ChildAction Controller方法中的跟踪语句不会反映在Trace.axd中。 然而,如果我直接点击http://localhost/Home/ChildAction,那么语句就会出现在跟踪中。

我做错了什么或者是否需要一些网站配置来允许跟踪工作以执行子操作以及他们调用的任何业务方法?

HomeController.cs:

public ActionResult Index()
{
    HttpContext.Trace.Write("blah");
    System.Diagnostics.Trace.WriteLine("blah diag");
    var b = new Business();
    b.DoStuff();
    return View();
}

public ActionResult ChildAction()
{
    HttpContext.Trace.Write("child action trace");
    System.Diagnostics.Trace.WriteLine("child action diag");
    var b = new Business();
    b.DoStuff();
    return Content("some content");
}

Index.cshtml:

<h2>Index</h2>
@{ Html.RenderAction("ChildAction"); }

的web.config:

<trace enabled="true" localOnly="false" mostRecent="true" pageOutput="false" requestLimit="1000" traceMode="SortByTime" writeToDiagnosticsTrace="false" />

<system.diagnostics>
<trace>
<listeners>
<add name="WebPageTraceListener" type="System.Web.WebPageTraceListener, System.Web, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>
</listeners>
</trace>
</system.diagnostics>

1 个答案:

答案 0 :(得分:0)

DGreen,也许您可​​以尝试使用Glimpse(website)。它有自己的TraceListener实现,可以为您解决这个问题。