asp.net-mvc - ASP.NET 跟踪在 MVC2 View 中工作吗?

标签 asp.net-mvc trace asp.net

我有一个 VS 2010 MVC2 .NET 4.0 Web 应用程序。在 Page 指令 (Trace="true) 和 Web.config 中都启用了 ASP.NET 跟踪:

<trace enabled="true" 
       requestLimit="10"
       pageOutput="true"
       traceMode="SortByTime" 
       localOnly="true" 
       writeToDiagnosticsTrace="true"
       />

Web.config 中还配置了标准跟踪监听器:
<trace autoflush="true" indentsize="4">
  <listeners>
    <add name="WebPageTrace" type="System.Web.WebPageTraceListener, System.Web, Version=4.0.30319.1, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
    <add name="TextWriterTrace" type="System.Diagnostics.TextWriterTraceListener" initializeData="textListener.log" />
  </listeners> 
</trace>

跟踪在 Controller 中工作正常,但是当我在 View (.aspx) 中添加跟踪时,没有任何显示:
<% System.Diagnostics.Trace.WriteLine("Message System.Diagnostics.Trace from View"); %>
<% Page.Trace.Write("Message Page.Trace from View"); %>

这应该有效吗?从 View 启用跟踪还需要其他什么吗?

谢谢

最佳答案

我相信这是由 this 回答的题。这里只是提供了一些答案......

When you called Trace.Write() in Web Forms, you were interacting with the Trace- Context class. This exists on your ViewPage in ASP.NET MVC, but this isn’t where you would want to write tracing statements. By the time you’ve passed the baton over to the view, there’s no logic there that you’d need to trace. Instead, you’d like to trace the logic embedded in your controllers

关于asp.net-mvc - ASP.NET 跟踪在 MVC2 View 中工作吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2738092/

相关文章:

.Net:如何抑制 TraceSource header ("SourceName TraceEventType: Id : ")?

asp.net - EntityFramework连接问题

c# - MVC 4 强类型 View 不传递 Controller 模型

asp.net-mvc - 如何检测不显眼的验证是否成功?

c# - 无法让 Ninject 在请求范围内处理对象

.net - .net v4 的全自动应用程序跟踪

x86 - 跟踪 x86 汇编代码中的堆栈

asp.net - 为 ViewModel 创建 View 帖子返回具有空外键属性的 ViewModel

javascript - 如何将多个变量从 typescript (angular.js)传递到 Web API(MVC)中的 Controller

c# - ASP.NET MVC : How do SimpleMembership, SQLSession 存储、身份验证和授权工作?