Library code snippets
Debug ASP.NET pages using Tracing
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.
Related articles
Related discussion
-
Export Datagrid to Excel with same formatting
by BarbaMariolino (1 replies)
-
how to design a template platform which can be used to create many different pages?
by polytheme (1 replies)
-
sending sms from pc
by sriraj20074 (0 replies)
-
Capture Video
by ess-image (23 replies)
-
DataGrid - How to display the content of a hidden TemplateField on mouseover
by DonCarnage (0 replies)
Related podcasts
-
StackOverflow uses ASP.NET MVC - Jeff Atwood and his technical team
Scott chats with Jeff Atwood of CodingHorror.com and most recently, StackOverflow.com. Jeff and Joel Spolsky and their technical team have created a new class of application using ASP.NET MVC. What works, what doesn't, and how did it all go down?
Events coming up
-
Jul
7
DTC 70-528 Session 7: Chapter 12
Greenwood Village, United States
Due to lack of interest of the 5th Monday meetup, we will continue as originally scheduled. The topic of the night will be "Chapter 12 - Creating ASP.NET Mobile Web Applications", taught by RJ Hatch. It is a fairly small chapter, so we can discuss other topics as well. Pizza and beverages will be provided on a donation basis.
This thread is for discussions of Debug ASP.NET pages using Tracing.