c# - 在 ASP.NET 应用程序中使用 System.Diagnostics.Debug

标签 c# asp.net visual-studio debugging

我试图在 ASP.NET 网络应用程序的输出窗口中查看代码中 foreach 循环的输出,但即使有有效数据,我也没有得到任何结果。对于这个问题,我使用 Google 进行了大量搜索,但没有任何效果。这是我的 ASPX 页面中的代码:

List<MyClass> myClasses = GetMyClasses();
foreach (MyClass myClass in myClasses)
{
    Debug.WriteLine(myClass.SomeProperty);
}

代码非常简单。当我调试此页面时,myClass.SomeProperty 具有我想要的值,但没有任何内容打印到输出窗口。我可能会错过什么?我无法使用 Response.Write,因为我的 Response 流正用于创建 Excel 文件。我也不想使用 Tracing。

更新

我的 web.config 文件中有这个:

<system.web>
    ...
    <compilation debug="true" targetFramework="4.0">
    ...
</system.web>

最佳答案

(抱歉没有完整的答案,但评论有点长)

有调试相关的功能。 (相关What does the optimize switch do)

  • 调试符号的生成
  • C# IL 优化
  • 抖动优化
  • DEBUG 条件定义。

你的问题需要的是 DEBUG 条件。我猜 debug="true" 开关只影响调试符号而不影响条件。


编辑: 嗯奇怪。 scottgu 说 http://weblogs.asp.net/scottgu/archive/2005/11/06/429723.aspx debug="true" 应该影响那个条件。

Note that the value of debug in a web app is driven by the value of the value in your web.config file.

关于c# - 在 ASP.NET 应用程序中使用 System.Diagnostics.Debug,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6335043/

相关文章:

c# - 当前的 .NET SDK 不支持面向 .NET Core 2.2。 (SDK 2.2.202)

c# - 如何使用 JQuery Ajax 调用从 Web 方法发送和检索数据?

visual-studio - VS 2015远程调试(msvsmon.exe)如何知道哪个w3wp进程附加到哪个iis服务

c# - 一对一关系不加载所有实体

c# - 使用 Fortran DLL 进行 NUnit 测试

c# - 摆脱 ListView 中的 1 像素填充/边框间隙?

asp.net - Internet Explorer 中的 session 状态问题!

asp.net - 所有 MVC 页面都失败并显示消息已添加具有相同键的项目

visual-studio - Visual Studio + svn : Working copies on network drive or local?

c# - 如何调试 Visual Studio 2010 中的属性集?