Programmatically enable trace debug for a page

Discussion in 'ASP .Net Security' started by Steve Lynch, Sep 29, 2006.

  1. Steve Lynch

    Steve Lynch Guest

    Is there a way to enable the trace output programmatically? For example in the
    web.config under I have:
    <trace enabled="true" localOnly="true" pageOutput="true" />

    but then I would like the code to decide at runtime (by a variable in the URL
    query string or something) if debug tracing output should be displayed for that
    page (similar to localOnly="false"). Any suggestions?
    Steve Lynch, Sep 29, 2006
    #1
    1. Advertising

  2. Page.Trace = true;

    ---
    Dominick Baier, DevelopMentor
    http://www.leastprivilege.com

    > Is there a way to enable the trace output programmatically? For
    > example in the
    > web.config under I have:
    > <trace enabled="true" localOnly="true" pageOutput="true" />
    > but then I would like the code to decide at runtime (by a variable in
    > the URL query string or something) if debug tracing output should be
    > displayed for that page (similar to localOnly="false"). Any
    > suggestions?
    >
    Dominick Baier, Sep 29, 2006
    #2
    1. Advertising

  3. Steve Lynch

    Steve Lynch Guest

    I wish it were that easy. The compiler gives me these errors:

    Error 1 Property or indexer 'System.Web.UI.Page.Trace' cannot be assigned to --
    it is read only H:\Code\VC#\TestApp\1.0\Default.aspx.cs 83 17 H:\...\2.0\

    Error 2 Cannot implicitly convert type 'bool' to 'System.Web.TraceContext'
    H:\Code\VC#\TestApp\1.0\Default.aspx.cs 83 30 H:\...\2.0\



    "Dominick Baier" <dbaier@pleasepleasenospam_leastprivilege.com> wrote in message
    news:...
    > Page.Trace = true;
    >
    > ---
    > Dominick Baier, DevelopMentor
    > http://www.leastprivilege.com
    >
    >> Is there a way to enable the trace output programmatically? For
    >> example in the
    >> web.config under I have:
    >> <trace enabled="true" localOnly="true" pageOutput="true" />
    >> but then I would like the code to decide at runtime (by a variable in
    >> the URL query string or something) if debug tracing output should be
    >> displayed for that page (similar to localOnly="false"). Any
    >> suggestions?
    >>

    >
    >
    Steve Lynch, Sep 29, 2006
    #3
  4. sorry - it is

    Trace.IsEnabled = true;

    ---
    Dominick Baier, DevelopMentor
    http://www.leastprivilege.com

    > I wish it were that easy. The compiler gives me these errors:
    >
    > Error 1 Property or indexer 'System.Web.UI.Page.Trace' cannot be
    > assigned to -- it is read only
    > H:\Code\VC#\TestApp\1.0\Default.aspx.cs 83 17 H:\...\2.0\
    >
    > Error 2 Cannot implicitly convert type 'bool' to
    > 'System.Web.TraceContext' H:\Code\VC#\TestApp\1.0\Default.aspx.cs 83
    > 30 H:\...\2.0\
    >
    > "Dominick Baier" <dbaier@pleasepleasenospam_leastprivilege.com> wrote
    > in message news:...
    >
    >> Page.Trace = true;
    >>
    >> ---
    >> Dominick Baier, DevelopMentor
    >> http://www.leastprivilege.com
    >>> Is there a way to enable the trace output programmatically? For
    >>> example in the
    >>> web.config under I have:
    >>> <trace enabled="true" localOnly="true" pageOutput="true" />
    >>> but then I would like the code to decide at runtime (by a variable
    >>> in
    >>> the URL query string or something) if debug tracing output should be
    >>> displayed for that page (similar to localOnly="false"). Any
    >>> suggestions
    Dominick Baier, Sep 30, 2006
    #4
  5. Steve Lynch

    Steve Lynch Guest

    Doh! that's pretty simple. I spent way too long looking for this, thanks.

    Here's what I did:

    1. Edit web.config to include:
    <trace enabled="true" localOnly="false" pageOutput="true" />

    2. Edit the @ Page directive to include:
    <%@ Page ... Trace="true" %>

    3. Edit the Page_Load function to include:
    Page.Trace.IsEnabled = false;
    try {
    Page.Trace.IsEnabled = (Request.QueryString["PAGE_DEBUG"].ToUpper() ==
    "TRUE");
    }


    Any suggestions for better/alternate ways to do this?



    "Dominick Baier" <dbaier@pleasepleasenospam_leastprivilege.com> wrote in message
    news:...
    > sorry - it is
    > Trace.IsEnabled = true;
    >
    > ---
    > Dominick Baier, DevelopMentor
    > http://www.leastprivilege.com
    >
    >> I wish it were that easy. The compiler gives me these errors:
    >>
    >> Error 1 Property or indexer 'System.Web.UI.Page.Trace' cannot be
    >> assigned to -- it is read only
    >> H:\Code\VC#\TestApp\1.0\Default.aspx.cs 83 17 H:\...\2.0\
    >>
    >> Error 2 Cannot implicitly convert type 'bool' to
    >> 'System.Web.TraceContext' H:\Code\VC#\TestApp\1.0\Default.aspx.cs 83
    >> 30 H:\...\2.0\
    >>
    >> "Dominick Baier" <dbaier@pleasepleasenospam_leastprivilege.com> wrote
    >> in message news:...
    >>
    >>> Page.Trace = true;
    >>>
    >>> ---
    >>> Dominick Baier, DevelopMentor
    >>> http://www.leastprivilege.com
    >>>> Is there a way to enable the trace output programmatically? For
    >>>> example in the
    >>>> web.config under I have:
    >>>> <trace enabled="true" localOnly="true" pageOutput="true" />
    >>>> but then I would like the code to decide at runtime (by a variable
    >>>> in
    >>>> the URL query string or something) if debug tracing output should be
    >>>> displayed for that page (similar to localOnly="false"). Any
    >>>> suggestions?

    >
    >
    Steve Lynch, Sep 30, 2006
    #5
  6. well - do you really want to include such functionality in a production app??

    thats quite dangerous -

    you can enable tracing when needed on a page or app basis - set the pageoutput="false"
    and you can access the trace data using http://server/app/trace.axd.

    I would also recommend to allow browsing of trace data only locally and use
    a terminal session to the web server to view the data.

    ---
    Dominick Baier, DevelopMentor
    http://www.leastprivilege.com

    > Doh! that's pretty simple. I spent way too long looking for this,
    > thanks.
    >
    > Here's what I did:
    >
    > 1. Edit web.config to include:
    > <trace enabled="true" localOnly="false" pageOutput="true" />
    > 2. Edit the @ Page directive to include:
    > <%@ Page ... Trace="true" %>
    > 3. Edit the Page_Load function to include:
    > Page.Trace.IsEnabled = false;
    > try {
    > Page.Trace.IsEnabled =
    > (Request.QueryString["PAGE_DEBUG"].ToUpper() ==
    > "TRUE");
    > }
    > Any suggestions for better/alternate ways to do this?
    >
    > "Dominick Baier" <dbaier@pleasepleasenospam_leastprivilege.com> wrote
    > in message news:...
    >
    >> sorry - it is
    >> Trace.IsEnabled = true;
    >> ---
    >> Dominick Baier, DevelopMentor
    >> http://www.leastprivilege.com
    >>> I wish it were that easy. The compiler gives me these errors:
    >>>
    >>> Error 1 Property or indexer 'System.Web.UI.Page.Trace' cannot be
    >>> assigned to -- it is read only
    >>> H:\Code\VC#\TestApp\1.0\Default.aspx.cs 83 17 H:\...\2.0\
    >>>
    >>> Error 2 Cannot implicitly convert type 'bool' to
    >>> 'System.Web.TraceContext' H:\Code\VC#\TestApp\1.0\Default.aspx.cs 83
    >>> 30 H:\...\2.0\
    >>>
    >>> "Dominick Baier" <dbaier@pleasepleasenospam_leastprivilege.com>
    >>> wrote in message
    >>> news:...
    >>>
    >>>> Page.Trace = true;
    >>>>
    >>>> ---
    >>>> Dominick Baier, DevelopMentor
    >>>> http://www.leastprivilege.com
    >>>>> Is there a way to enable the trace output programmatically? For
    >>>>> example in the
    >>>>> web.config under I have:
    >>>>> <trace enabled="true" localOnly="true" pageOutput="true" />
    >>>>> but then I would like the code to decide at runtime (by a variable
    >>>>> in
    >>>>> the URL query string or something) if debug tracing output should
    >>>>> be
    >>>>> displayed for that page (similar to localOnly="false"). Any
    >>>>> suggestions?
    Dominick Baier, Sep 30, 2006
    #6
  7. Steve Lynch

    Steve Lynch Guest

    You're right, but this is not really a "production app" it's just a support
    system on an intranet with no sensitive data. Thanks for the replies.


    "Dominick Baier" <dbaier@pleasepleasenospam_leastprivilege.com> wrote in message
    news:...
    > well - do you really want to include such functionality in a production app??
    >
    > thats quite dangerous -
    > you can enable tracing when needed on a page or app basis - set the
    > pageoutput="false" and you can access the trace data using
    > http://server/app/trace.axd.
    >
    > I would also recommend to allow browsing of trace data only locally and use a
    > terminal session to the web server to view the data.
    >
    > ---
    > Dominick Baier, DevelopMentor
    > http://www.leastprivilege.com
    >
    >> Doh! that's pretty simple. I spent way too long looking for this,
    >> thanks.
    >>
    >> Here's what I did:
    >>
    >> 1. Edit web.config to include:
    >> <trace enabled="true" localOnly="false" pageOutput="true" />
    >> 2. Edit the @ Page directive to include:
    >> <%@ Page ... Trace="true" %>
    >> 3. Edit the Page_Load function to include:
    >> Page.Trace.IsEnabled = false;
    >> try {
    >> Page.Trace.IsEnabled =
    >> (Request.QueryString["PAGE_DEBUG"].ToUpper() ==
    >> "TRUE");
    >> }
    >> Any suggestions for better/alternate ways to do this?
    >>
    >> "Dominick Baier" <dbaier@pleasepleasenospam_leastprivilege.com> wrote
    >> in message news:...
    >>
    >>> sorry - it is
    >>> Trace.IsEnabled = true;
    >>> ---
    >>> Dominick Baier, DevelopMentor
    >>> http://www.leastprivilege.com
    >>>> I wish it were that easy. The compiler gives me these errors:
    >>>>
    >>>> Error 1 Property or indexer 'System.Web.UI.Page.Trace' cannot be
    >>>> assigned to -- it is read only
    >>>> H:\Code\VC#\TestApp\1.0\Default.aspx.cs 83 17 H:\...\2.0\
    >>>>
    >>>> Error 2 Cannot implicitly convert type 'bool' to
    >>>> 'System.Web.TraceContext' H:\Code\VC#\TestApp\1.0\Default.aspx.cs 83
    >>>> 30 H:\...\2.0\
    >>>>
    >>>> "Dominick Baier" <dbaier@pleasepleasenospam_leastprivilege.com>
    >>>> wrote in message
    >>>> news:...
    >>>>
    >>>>> Page.Trace = true;
    >>>>>
    >>>>> ---
    >>>>> Dominick Baier, DevelopMentor
    >>>>> http://www.leastprivilege.com
    >>>>>> Is there a way to enable the trace output programmatically? For
    >>>>>> example in the
    >>>>>> web.config under I have:
    >>>>>> <trace enabled="true" localOnly="true" pageOutput="true" />
    >>>>>> but then I would like the code to decide at runtime (by a variable
    >>>>>> in
    >>>>>> the URL query string or something) if debug tracing output should
    >>>>>> be
    >>>>>> displayed for that page (similar to localOnly="false"). Any
    >>>>>> suggestions?

    >
    >
    Steve Lynch, Oct 2, 2006
    #7
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Rukmal Fernando
    Replies:
    4
    Views:
    837
    Richard Grimes [MVP]
    Oct 27, 2003
  2. DesignerX
    Replies:
    1
    Views:
    346
    David Wier
    Aug 13, 2003
  3. Patrick
    Replies:
    1
    Views:
    636
  4. Matthias S.
    Replies:
    1
    Views:
    634
    Daniel Fisher\(lennybacon\)
    Nov 30, 2005
  5. Jiho Han
    Replies:
    0
    Views:
    499
    Jiho Han
    Aug 22, 2006
Loading...

Share This Page