第二次请求后 HttpContext.Current.Trace.IsEnabled 莫名其妙地变成 false

发布于 2024-12-14 06:48:10 字数 669 浏览 3 评论 0原文

在我的 web.config 中,启用了跟踪。在第一个请求中,页面跟踪显示。然后在第二页上,Trace.IsEnabled 变为 false。我不记得以前见过这种行为。我已经搜索了所有源代码,但找不到任何可能禁用它的对 Trace 的引用。

参考号web.config

<trace enabled="true" localOnly="false" pageOutput="true" />

这是我目前的工作,在 global.asax 中,我添加了它

protected void Session_Start(object sender, EventArgs e)
{
if(HttpContext.Current.Trace.IsEnabled) //True on 1st request
    Session["TraceEnabled"] = true;

,然后将其添加到自定义基页面中的早期事件中。

if (Session["TraceEnabled"] != null)
    HttpContext.Current.Trace.IsEnabled = true;

然后跟踪按预期恢复。

为什么跟踪可能会自行关闭?我宁愿解决根本问题,也不愿做一些笨拙的工作。

In my web.config, trace is enabled. On the 1st request, in page trace shows up. Then on the second page, Trace.IsEnabled becomes false. I don't recall ever seeing this behavior before. I've search the source code everything and I can't find any references to Trace that might be disabling it.

Ref. web.config

<trace enabled="true" localOnly="false" pageOutput="true" />

Here is my work around for the moment, in global.asax, I added this

protected void Session_Start(object sender, EventArgs e)
{
if(HttpContext.Current.Trace.IsEnabled) //True on 1st request
    Session["TraceEnabled"] = true;

I then added this to an early event in a custom base page.

if (Session["TraceEnabled"] != null)
    HttpContext.Current.Trace.IsEnabled = true;

Trace then resumes as expected.

Why might trace turn itself off? I'd rather fix the root problem than having a clunky work around.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

花伊自在美 2024-12-21 06:48:10

是否尝试过增加配置文件中的 requestLimit 属性?

<configuration>
  <system.web>
    <trace enabled="true" pageOutput="false" requestLimit="40" localOnly="false"/>
  </system.web>
</configuration>

Have tried to increase the requestLimit attribute on your configuration file?

<configuration>
  <system.web>
    <trace enabled="true" pageOutput="false" requestLimit="40" localOnly="false"/>
  </system.web>
</configuration>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文