Re: Programmatically enable trace debug for a page




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@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:4580be63154be8c8b24b2feceb13@xxxxxxxxxxxxxxxxxxxxx
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@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx> wrote
in message news:4580be63154b68c8b2437342f3a9@xxxxxxxxxxxxxxxxxxxxx

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@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx>
wrote in message
news:4580be631548a8c8b210d9d3cf9c@xxxxxxxxxxxxxxxxxxxxx

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?




.