Dr. Dobb's is part of the Informa Tech Division of Informa PLC

This site is operated by a business or businesses owned by Informa PLC and all copyright resides with them. Informa PLC's registered office is 5 Howick Place, London SW1P 1WG. Registered in England and Wales. Number 8860726.


Channels ▼
RSS

The Debug Attribute


The Debug Attribute

ASP.NET applications can take advantage of several @ directives to configure the environment in which they are called to run. One of the most frequently used is the @Page directive, which sets up the runtime environment for the page and controls page compilation, language, culture, and tracing. The @Page directive can be used only in .aspx pages and originates a compile error if used with other types of ASP.NET resources such as controls and web services.

Each .aspx file is allowed to include at most one @Page directive. Although not strictly necessary from the syntax point of view, the directive is realistically required by all pages of some complexity.

@Page features about 30 attributes that can be logically grouped in three categories: compilation, overall page behavior, and page output. Each ASP.NET page is transformed into a class and compiled upon first request. The HTML actually served to the browser is generated by the methods of such a dynamically generated class. Using the @Page directive you can specify the name of the class, its base class, and even the compiler options you want to be applied. If you're using Visual Basic .NET, then you can also set class level attributes such as Explicit and Strict.

The source code of the .aspx page that is actually served to the user is not visible by default. The source code-written in the language defined by the Language attribute-is created in a temporary folder and deleted right after having been compiled into an assembly. If you want to take a look at this source code, you can do as follows.

  • Set the debug attribute on the @Page directive toTrue.
  • Open the "Temporary ASP.NET Files" folder and locate your web application.
  • Go deeper by a couple of directory levels and locate the XML file that begins with the name of the .aspx you invoked.
  • Open the XML file and read the assem attribute from the root node.
  • The random sequence of characters you read are the name of the file you're looking for. The extension of the file is .vb or .cs according to the language of choice. If no language is specified, then ASP.NET defaults to Visual Basic .NET.

It is essential that the page contains the debug attribute set to true.

<%@ Page debug="true" %>

This is the only programmable element that allows you to control whether the temporary file is deleted or not. The "Temporary ASP.NET Files" folder is located under

c:\winnt\microsoft.net\framework\v.1.x.xxxx.x\

where the version number is the version of the currently installed ASP.NET engine. For version 1.0, the full version number is 1.0.3705.0. The temporary ASP.NET folder contains a directory for each web application. Locate your own and drill down for a couple of subdirectories. The names of these subdirectories are randomly generated and obey to a logic that is not documented.

If you're trying to access the actual directory with the source code programmatically, then you can use the HttpRuntime.CodegenDir property to know the name of the temporary folder for your application.

Locating the source file is not that hard, and once you open it you are exposed to the wonders of ASP.NET. My two-cent opinion is that there's no better way to grab the essence of ASP.NET!


Dino Esposito is Wintellect's ADO.NET and XML expert, and a trainer and consultant based in Rome, Italy. Dino is a contributing editor to Windows Developer Magazine and MSDN Magazine, and the author of several books for Microsoft Press including Building Web Solutions with ASP.NET and ADO.NET and Applied XML Programming for .NET. Contact Dino at [email protected].



Related Reading


More Insights






Currently we allow the following HTML tags in comments:

Single tags

These tags can be used alone and don't need an ending tag.

<br> Defines a single line break

<hr> Defines a horizontal line

Matching tags

These require an ending tag - e.g. <i>italic text</i>

<a> Defines an anchor

<b> Defines bold text

<big> Defines big text

<blockquote> Defines a long quotation

<caption> Defines a table caption

<cite> Defines a citation

<code> Defines computer code text

<em> Defines emphasized text

<fieldset> Defines a border around elements in a form

<h1> This is heading 1

<h2> This is heading 2

<h3> This is heading 3

<h4> This is heading 4

<h5> This is heading 5

<h6> This is heading 6

<i> Defines italic text

<p> Defines a paragraph

<pre> Defines preformatted text

<q> Defines a short quotation

<samp> Defines sample computer code text

<small> Defines small text

<span> Defines a section in a document

<s> Defines strikethrough text

<strike> Defines strikethrough text

<strong> Defines strong text

<sub> Defines subscripted text

<sup> Defines superscripted text

<u> Defines underlined text

Dr. Dobb's encourages readers to engage in spirited, healthy debate, including taking us to task. However, Dr. Dobb's moderates all comments posted to our site, and reserves the right to modify or remove any content that it determines to be derogatory, offensive, inflammatory, vulgar, irrelevant/off-topic, racist or obvious marketing or spam. Dr. Dobb's further reserves the right to disable the profile of any commenter participating in said activities.

 
Disqus Tips To upload an avatar photo, first complete your Disqus profile. | View the list of supported HTML tags you can use to style comments. | Please read our commenting policy.