在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>