ASP.NET Architecture, Part 1 - Applying Page Directives
(Page 7 of 8 )
Most likely if you are a classic ASP developer, you have used directives such as @ Include and @ Language. The @ Include directive instructs the ASP runtime to include a particular file inline with the page. The @ Language directive tells the runtime to employ a specific script interpreter located within the <% %> render blocks. Directives provide easy ways for developers to determine declaratively how various aspects of an application will ultimately behave. For example, in addition to the @ Language directive, classic ASP provided only four directives:
@ Codepage Used in globalization to set the code page for an ASP page
@ EnableSessionState Used to disable session state for a specified page
@ LCID Used to set the locale identifier for an ASP page
@Transaction Used to specify how a page participates in COM+ transactions
ASP.NET has added numerous directives for controlling page behavior, page configuration, and many other tasks. Table 6-1 presents a partial list of new directives included with ASP.NET. Note that in the Values column, T/F stands for true or false.
Attribute | Values | Meaning |
@ Page | T/F | Defines page-specific attributes used by ASP.NET compilers and the CLR to determine page behavior. |
AutoEventWireup | T/F Default is set in the <pages> segment of the Machine.config or Web.config file | Determines whether handlers are set up automatically. Default is true. |
Buffer | T/F | Specifies whether rendered output is buffered before sending it to clients, or sent as it is rendered. |
ClassName | Can be any class name | Determines name of page when dynamically compiling the page. This works either with or without CodeBehind. |
CodeBehind | File name of CodeBehind class | Visual Studio .NET uses this attribute for locating the CodeBehind class and compiling during a build operation. ASP.NET does not use this attribute. |
CodePage | Any code page | The same in both ASP and ASP.NET. |
CompilerOptions | A string containing valid compiler options | Allows developers to specify compiler options for a specified page. |
ContentType | Any valid MIME type | Sets the MIME type for page output. |
Debug | T/F Default is set in the <compilation> section of the Machine.config or Web.config file | Determines whether pages are compiled with debug symbols or not. Default is false. |
Description | Any string | Provides a text description of the page. The ASP.NET runtime ignores this attribute. |
EnableSessionState | T/F Default is set in the <pages> section of the Machine.config or Web.config file | Determines whether a page request initiates a new session and whether or not the page can access or modify data saved in an existing session. Default is true. |
EnableViewState | T/F Default is set in the <pages> section of the Machine.config or Web.config file | Specifies whether ViewState is enabled for the page. Default is true. |
EnableViewStateMac | T/F Default is set in the <pages> section of the Machine.config or Web.config file | Determines whether ASP.NET executes a machine authentication check on the content of a hidden form field that is used to store ViewState and to ensure it is not modified on the client. Default is false. |
Table 1 ASP.NET Page Directives
NOTE: The list of directives in Table 1 is incomplete. Many other equally important directives exist, such as Inherits, ResponseEncoding, LCID, Strict, and Transaction. You can search for these directives in Visual Studio .NET Help.
Here is a brief example of how you would use the Page directive:
<%@ Page debug="true" %>
Another example sets the trace directive:
<%@ Page trace="true" %>
Other directives include the @ Implements directive, employed to implement a defined interface from within an ASP.NET page. In addition, use the @ Register directive to register user controls and custom server controls on an ASP.NET page.
Come back this Friday, 27/02/2004, for part two of ASP.NET Architecture. This is chapter six of .NET & J2EE Interoperability, by Dwight Peltzer (McGraw-Hill/Osborne, ISBN 0-07-223054-1, 2004). Buy this book now.
|
Next: Code-Behind Feature >>
More ASP.NET Articles
More By McGraw-Hill/Osborne