Programmatically enable trace debug for a page

S

Steve Lynch

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?
 
S

Steve Lynch

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\
 
S

Steve Lynch

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?
 
D

Dominick Baier

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?

sorry - it is
Trace.IsEnabled = true;
 
S

Steve Lynch

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 said:
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?

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

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?
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,767
Messages
2,569,572
Members
45,045
Latest member
DRCM

Latest Threads

Top