Members

Technology Zones

IBM Learning Center

Articles

Hosted By

MaximumASP

Info

Rated
Read 25,400 times

Related Categories

Debug ASP.NET pages using Tracing

julesr

In Classic ASP one might debug some code using VB Script:

Response.Write strSQL
Response.End()

and the comment/uncomment the code accordingly. This was a bit of a pain during the development process. In ASP.NET, one can use the Trace feature which simplifies matters somewhat. Page-level tracing can be set in the Page directive on the ASPX page:

<%@ Page Language="c#" Trace="true"%>

and in the code one could use:

string strSQL="select * from " + Table + " " + WhereClause + " order by " + OrderingColumn;
Trace.Write("SQL",strSQL);

When the page is run in the browser, you'll see:

So, you'd be able to see the SQL that is executed. By using Trace.Warn instead of Trace.Write, the line would be highlighted in Red. When the application is deployed, you'd simply disable tracing by setting the Trace attribute to false. If you have many pages that you wish to trace, then it may be more viable to set the tracing in your web.config file:

<system.web>
    <trace enabled="true" requestLimit="20" pageOutput="true" traceMode="SortByCategory" localOnly="true" />
</system.web>

So, you can easily enable/disable tracing as required.

I've been a freelance web developer since Feb '00. Prior to that, I'd spent most of my working life in the pub trade. I'd also worked as a security guard in a local factory. Luckily, I was able to my laptop into work. It was there that I used to spend my 12 hour shifts learning about web development! Over the years, I have worked on a lot of interesting sites. You can see a list of more recent sites in my portfolio. And acquired a string set of technical skillsets. These include: * ASP/VB Script * ASP.NET/C# * SQL Server 2000/Access 2000 * XML/XSLT It should be noted that my design skills are practically zero. Jojo, from the DW newsgroup, did the design for this site. I just put it all together in Dreamweaver MX. I don't really have much time for hobbies or pastimes. When I do get some spare time, I enjoy playing scrabble, doing crosswords and playing golf. At one time, I got down to a single-figure handicap at golf. But, I'd struggle to maintain that now!

Comments