Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3308568
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T21:32:13+00:00 2026-05-17T21:32:13+00:00

I have a custom control that is show only with a given set of

  • 0

I have a custom control that is show only with a given set of config values.

I want to capture the trace.axd data and output it to this control.

web.config

writeToDiagnosticsTrace="true" 
...
<listeners>
 name="WebPageTraceListener"
    type="System.Web.WebPageTraceListener, System.Web, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" 
</listeners>

I want to be able to load the trace.axd file in a usercontrol. Then have that usercontrol be loaded whenever needed.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T21:32:13+00:00Added an answer on May 17, 2026 at 9:32 pm

    I have a working solution, with two caveats:

    First, it will always render the trace output too early, because it’s too late to do that in a Page.ProcessRequest() override (the Response object has already been cleaned up), so we’re forced to do it during the Render phase, which means we’ll miss some messages (most notably EndRender).

    Implementing that behavior in a control exacerbates the problem, since we’d have to ensure our control is the last thing to render on the page in order to avoid missing more messages. For that reason, I chose to implement a custom page class instead of a custom control class. If you absolutely need a control class, it should be easy to convert (but leave me a word here if you need help).

    Second, the profiler object that owns the data, HttpRuntime.Profile, is internal to the System.Web assembly, and of course the trace rendering routine is private to the Page class. So we have to abuse reflection, break encapsulation, and basically be evil in order to do what you want. If the ASP.NET trace implementation changes in the slightest, we’re SOL.

    That said, here’s the traceable page class:

    using System;
    using System.Reflection;
    using System.Web;
    using System.Web.UI;
    
    namespace StackOverflow.Bounties.Web.UI
    {
        public class TraceablePage : Page
        {
            /// <summary>
            /// Gets or sets whether to render trace output.
            /// </summary>
            public bool EnableTraceOutput
            {
                get;
                set;
            }
    
            /// <summary>
            /// Abuses reflection to force the profiler's page output flag
            /// to true during a call to the page's trace rendering routine.
            /// </summary>
            protected override void Render(HtmlTextWriter writer)
            {
                base.Render(writer);
                if (!EnableTraceOutput) {
                    return;
                }
    
                // Allow access to private and internal members.
                BindingFlags evilFlags
                    = BindingFlags.Instance | BindingFlags.Static
                    | BindingFlags.Public | BindingFlags.NonPublic;
    
                // Profiler profiler = HttpRuntime.Profile;
                object profiler = typeof(HttpRuntime)
                    .GetProperty("Profile", evilFlags).GetGetMethod(true)
                    .Invoke(null, null);
    
                // profiler.PageOutput = true;
                profiler.GetType().GetProperty("PageOutput", evilFlags)
                    .GetSetMethod(true).Invoke(profiler, new object[] { true });
    
                // this.ProcessRequestEndTrace();
                typeof(Page).GetMethod("ProcessRequestEndTrace", evilFlags)
                    .Invoke(this, null);
    
                // profiler.PageOutput = false;
                profiler.GetType().GetProperty("PageOutput", evilFlags)
                    .GetSetMethod(true).Invoke(profiler, new object[] { false });
            }
        }
    }
    

    And here’s its test page, which uses an AutoPostBack check box to demonstrate its behavior across postbacks:

    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="TestTracePage.aspx.cs"
        Inherits="StackOverflow.Bounties.Web.UI.TestTracePage" %>
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title>TraceablePage Test</title>
    </head>
    <body>
        <form id="form" runat="server">
        <h2>TraceablePage Test</h2>
        <p>
            <asp:CheckBox id="enableTrace" runat="server"
                AutoPostBack="True" Text="Enable trace output"
                OnCheckedChanged="enableTrace_CheckedChanged" />
        </p>
        </form>
    </body>
    </html>
    

    And the code behind:

    using System;
    using System.Web.UI;
    
    namespace StackOverflow.Bounties.Web.UI
    {
        public partial class TestTracePage : TraceablePage
        {
            protected void enableTrace_CheckedChanged(object sender, EventArgs e)
            {
                EnableTraceOutput = enableTrace.Checked;
            }
        }
    }
    

    The test page renders like this on first load:

    Trace disabled

    Checking the box posts back and renders the trace output:

    Trace enabled

    Clearing the check box again suppresses the trace output, as expected.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a custom control that exposes a property. When I set it using
I have a custom control that implements IPostBackEventHandler. Some client-side events invoke __doPostBack(controlID, eventArgs).
I have a custom control that inherits from WebControl and implements IValidator, but I
I have a custom control that has the following prototype. Type.registerNamespace('Demo'); Demo.CustomTextBox = function(element)
I have a custom control that shows a value obtained from the database (the
The background is I have a custom control that is a asp:Menu that is
I have a custom user control that contains asp:ValidationSummary . It is placed on
I have a custom DataGridView column that uses an embedded control that pops up
I have two custom controls that are analogous to a node and the control
I need only to show a custom control (a clock with rotating hands) and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.