Asp. NET page Support instructions

Source: Internet
Author: User
Tags net serialization serialization

Processing instructions for the page

The processing of page directives is used to configure the Run-time environment that executes the Page. In asp., the directive can be anywhere on the page, but a good and common habit is to place it at the beginning of the File. In addition to this, the name of the page directive is case-insensitive, and the Directive's attribute (attribute) value does not have to be quoted. @Page is the most important and most commonly used instruction in asp. Table 3.4 Lists all the asp. "101~102"

Table 3.4 ASP. NET page Support instructions




Used to link an assembly to the current page or user control


Used to define CONTROL-SPECIFIC properties (attribute) that control the behavior of the control compiler


Used to indicate the current page or the current user control implementation of the Specified. NET Framework interface


Used to explicitly import a namespace into a page or user control


Used to indicate that the current page is identified as an asp. Net Master Page (see Chapter 6th). Asp. NET 1.x does not support this directive


When you access an asp. NET Master page through the master property, it provides a way for the master page to create a strongly typed reference (see Chapter 6th). Asp. NET 1.x does not support this directive


The output caching policy used to control the page or user Control (see Chapter 16th)


Used to define PAGE-SPECIFIC properties to control the behavior of the page editor and language parser that handles the page


Provides a way to get previous page strongly typed references, which can be accessed from the previous page through the PreviousPage property


Used to link a page or user control to the current page or user control


Used to create a custom label in a page or Control. New tags, including prefixes and names, associate namespaces with user-defined controls

All directives can be declared in pages and controls except @page, @PreviousPageType, @Master, @MasterType, and @control. @Page and @Control are mutually exclusive: @Page can only be used in. aspx files, and @control directives can only be used in. ascx files. @Master is used to define a very special Page-the master Page.

The syntax for processing instructions is special, but is consistent for all instruction Types. Multiple attributes (attribute) must be separated by whitespace, and the equal sign (=) between the attribute and the value cannot be blank, as Follows:

<%@ directive_name attribute= "value" [attribute= "value" ...]%> "103"

Each instruction has its own typed set of Properties. Assigning a value of the wrong type to a property, or using the wrong property in a property, can result in a compilation Error.

Important: the attribute content of an instruction is always parsed in plain text form. however, for some properties, you should include values that can be resolved to a SPECIFIC. NET framework Type. When an asp. NET page is parsed, all Directive properties
will be extracted and stored in a dictionary. The name and number of the property must match the pattern that corresponds to the Directive. As long as the property value represented by the string can be converted to the target type, it is valid. For example, if a property only accepts a Boolean (boolean) type of value, only true and false are Valid.

@Page Instructions

@Page directives can only be used in. aspx pages and can cause compilation errors if used in other asp. net pages, such as controls and Web Services. Each. aspx file can contain a maximum of one @page Instruction. Although from a grammatical point of view, it is not necessary to force a requirement to specify the directive, but practically all complex pages do So.

The @Page directive has approximately 30 attributes, which logically fall into three categories: compile (see table 3.5), page overall behavior (see table 3.6), and page output (see table 3.7). Each ASP is compiled on the first request, and the HTML that is actually sent to the browser is generated by the methods of the class, and these classes are generated dynamically. The properties listed in Table 3.5 are used to adjust the compiler parameters and to select the language to Use.

Table 3.5 @page Directive properties for page compilation




Used to specify the name of the dynamically generated class when the page is Requested. It must be a class name without the namespace information


The path that is used to prompt the current page code-behind class. The class file must be deployed on the web Server. Asp. NET 1.x does not support this property


The properties used by Visual Studio. NET 2003 to prompt the path of the current page Code-behind class. The class file is compiled into a deployable assembly (the CodeFile attribute should be used for 2.0 or later versions of Asp.)


The base class name used to specify the base class of the page and its associated code-behind class. This property is optional, but if you use the CodeFile property, you must specify the Property. Asp. NET 1.x does not support this property


Used to indicate whether the current page is compiled at run Time. Asp. NET 1.x does not support this property


A series of compiler command-line arguments for compiling the current page


A Boolean value that indicates whether the page should be compiled with debug symbols


A Boolean value that determines whether visual Basic's Option Explicit mode is set to ON when compiling the Page. Option explicit forces programmers to explicitly declare all Variables. If the language selected on the current page is not visual Basic. NET, This property will be ignored


Used to define the base class to inherit from the current page, which can be any class derived from the page class


The language used to prompt the code in the inline code block (<% ...%>) and the <script> section at compile Time. Supported languages include Visual Basic. NET, C #, JScript. NET and J #. If not specified otherwise, the default setting is Visual Basic. NET

Continuation table




Used to determine whether the runtime should generate line pragmas in source code (lines Pragma)


The master page that is used to indicate the current Page. Asp. NET 1.x does not support this property


Used to indicate the source file path that contains the base class specified by the implementation inherits. Visual Studio and other rapid application development (RAD) designers do not use this property


A Boolean value that determines whether visual Basic's Option Strict is set to on when compiling the current Page. If option Strict is turned on, only type-safe conversions are allowed, and implicit type conversions that can result in data loss are prohibited (in this case, their behavior is consistent with C #). If the language selected on the current page is not visual Basic. NET, This property will be ignored


A Boolean value that indicates whether the trace feature is turned On. If tracing is enabled, additional information is appended to the output of the Page. The default value is False


When tracing is enabled, prompts the current page to track how messages are Displayed. Valid values are SortByTime and sortbycategory. The default value for this property is SortByTime if the trace function is turned on


Prompts the compiler for warning levels, and the compilation process aborts when the specified level is Reached. Valid values are 0~4


Note that the default values for the explicit and strict properties are read from the Application's configuration File. Get settings for an asp. NET application by merging settings at all machine, application, and folder Levels. This indicates that we can also control the default values for the explicit and strict properties. If you do not change the default configuration information (that is, configuration information that is created when The. NET framework is installed), explicit and strict are set to true by Default. If you delete all of the settings associated with it in each configuration file, the values will become False.

The properties listed in Table 3.6 control the overall behavior of the page and the features that are supported in some way. For example, we can set a custom error page, disable session state, and control the behavior of the Page's handling of things.

Table 3.6 @page Directive properties for controlling page behavior




The properties of the Boolean type. If set to true, the current page is allowed to execute on a single-threaded apartment (STA) Thread. This setting enables the page to invoke COM + 1.0 components, as well as components developed with Visual Basic 6.0 that require access to unmanaged ASP built-in objects (this topic is discussed in Chapter 14th)


If set to true, the resulting page class will be born in IHttpAsyncHandler instead of having IHttpHandler add some of the built-in non-synchronous functionality to the Page. Asp. NET 1.x does not support this property

Continuation table




Used to define the time-out (in Seconds) to use when processing asynchronous tasks. The default is 45 SECONDS. Asp. NET 1.x does not support this property


A property of the Boolean type that indicates whether the Page's events are Enabled. The default is True. Use Visual Studio. Net-developed page will set this property to false, and the Page's events will be bound to the handler individually


A Boolean property that determines whether HTTP response buffering is Enabled. The default value is True


Used to provide a textual description of the current Page. Asp. NET page parser ignores this property and uses only the composition document to describe


A Boolean property that determines whether the current page generates an implied field and buffers the input fields that support event data Validation. The default value is True. Asp. NET 1.x does not support this property


Used to define how the current page processes session Data. If set to true, the session state can be Read/write. If set to false, the application cannot use session Data. finally, If set to readonly, you can only read session data, not change


A property of type Boolean that indicates whether view state is persisted between page Requests. View state is the context of a page call that holds a collection of current page state values between round trips (this is explained in chapter 15th)


A property of type Boolean that indicates whether the current page applies a theme to the embedded Control. The default value is True. Asp. NET 1.x does not support this property


A Boolean property that indicates whether Asp. NET generates an authentication code for a specific computer and appends it to the Page's view state (in addition to Base64 encoding). The MAC in the property name represents "computer authentication check" (machine Authentication check,mac). If this property is set to true, the ASP is on Postback. NET checks the view state of the authentication code to ensure that it has not been tampered with on the client


Defines a destination url, which points to a hint Page. User is redirected to this location when an unhandled exception occurs on the page


Used to indicate whether the client Browser's scroll bar position is restored after a postback. The default value is Fasle


A Boolean property that indicates whether the current page supports Internet Explorer 5 or a later version of the smart navigation Feature. Smart navigation makes the page refresh without losing scrolling position and element focus


Used to indicate the name of the theme (or style sheet Theme) selected for the current Page. Asp. NET 1.x does not support this property

Continuation table




Used to indicate whether the current page supports or needs things. Valid values are: Disabled, notsupported, supported, required, and Requiresnew. By default, transaction support is disabled


A property of type Boolean that indicates whether to perform request Validation. If set to True,asp. NET checks all input data against a hard-coded list of potentially dangerous values. This feature helps reduce the risk of Cross-site scripting attacks on Pages. The default value is True. Asp. NET 1.0 does not support this feature


Used to indicate how the view state is Encrypted. There are three possible enumeration values: Auto, always, and Never. The default is auto, which indicates that view state is encrypted only when the control requires it. Note that each requested page processing encrypts the view data, which creates some additional overhead for the server


The properties listed in Table 3.7 are used to control the format of output information generated for a page. For example, we can set the content type of a page, or localize the output as much as Possible.

Table 3.7 @page Directive properties for controlling output




Used to indicate the browser to which the Asp. NET server control renders its content


Used to indicate the corresponding code page Value. This property is set only if you are using a code page to create the page instead of using the default code page of the Web server on which the page is Running. In this case, set the property to the code page of the development computer. A code page is a collection of symbols, including numbers, punctuation, and other Symbols. Different language code pages will differ


Used to define the content type of the response as a standard MIME type. Support for any valid HTTP content type string


Used to indicate the culture setting of the current Page. Culture information includes the writing and sorting system, calendar, and currency formats. The property value must be a culture-related name, that is, it must contain language and country Information. en-us, for example, is a valid value, and in itself is considered a state-irrelevant


A 32-bit value that defines the area identifier for the Page. by default, ASP. NET uses the regional settings of the Web server


The name of the encoding scheme used to indicate the current Page. This value is used to set the CharSet property of the Content-type http header. in-house, ASP. NET will treat all strings as Unicode


Used to indicate the title of the current Page. It does not work for a typical page, because you can use the HTML <title> tag, which is defined to help developers to set a title for the content page without access to <title> (depending on the structure design of the master Page)

Continuation table




Specifies the name of the default zone information used by the resource manager (Resource Manager) to find culture-specific resources at run time

It is not difficult to see that many of the properties in table 3.7 are related to the localization of the Page. Asp. NET (more generally speaking, the,) is a great way to simplify the task of building multi-lingual, internationalized Applications. The 5th chapter explores the issue in Depth.

@Assembly Instructions

The @Assembly directive is used to link an assembly to the current page so that its classes and interfaces can be used on that Page. When asp. net compiles the page, there are several default assemblies that are linked in. therefore, You should use this directive only if you need to link a non-default assembly. Table 3.8 lists The. net assemblies that are automatically supplied to the Compiler. "108"

Table 3.8 Default linked assemblies

assembly file Name



Provides core functionality of The. NET framework, including type, appdomain, and Run-time Services


Provides another set of system services, including regular expressions, compilation, local methods, file input/output, and networking


A class that defines the Read/write profile Data. Asp. NET 1.x does not contain this Assembly


Defines the data container and data access classes, including the entire ADO framework


Implements GDI + functionality


Provides classes that allow interaction between serviced components and COM +


The assembly implements the Asp. net core services, controls, and classes


The assembly implements the Asp. NET core mobile services, controls, and classes. The assembly is not included in the version 1.0 installation of The.


Contains the core code that drives the Web service to run


Implements the XML capabilities of THE. NET framework


Defines The. NET serialization capabilities of the Api. In an asp. NET 2.0 application, this assembly is one of the most frequently used assemblies added by the Developer. This assembly was not introduced in versions prior to asp. NET 3.5


Defines classes and structs for Windows Communication Foundation (WCF) Services. This assembly was not introduced in versions prior to asp. NET 3.5


Defines the additional classes that asp. net and Ajax need to Use. This assembly was not introduced in versions prior to asp. NET 3.5


Defines the classes that the workflow (Workflow) and WCF services Require. This assembly was not introduced in versions prior to asp. NET 3.5

In addition to these assemblies, ASP. The net runtime also automatically links the assemblies in the bin subdirectory of the Web application to all Pages. You can change, extend, or restrict the default list of assemblies by editing the settings in the Computer-level Web. config file. This change will be used for all asp. NET applications running on the Web Server. In addition, you can edit the Application-specific web. config file to customize the assembly list for each application one by One. To prevent all assemblies that exist in the bin directory from being linked to the page, you can remove the following code from the root configuration file:

<add assembly= "*"/> "109"

Caution: for an asp. net application, the entire set of configuration properties is set at the computer level. initially, all applications running on the server computer share the same settings. A stand-alone application can override some of these settings in its own Web. config File. Each application can place a Web. config file in its root directory and place other specialized Web. config copies in the application-specific subdirectory. The settings for each page depend on all the settings in all profiles found from the computer level to the current folder Path. In asp. net 1.x, the Machine.config file contains the full default settings Tree. In asp. net 2.0, the settings data related to the Web application were moved to the Website. config file, which is in the same system folder as Machine.config. This folder is called CONFIG, which is located under the asp. NET installation path:%windows%\microsoft. Net\framework\[version].

To link the desired assembly to a page, use the following syntax:

<%@ Assembly name= "assemblyname"%>

<%@ Assembly src= "assembly_code.cs"%>

The @Assembly directive supports two mutually exclusive attributes: Name and src. Name is used to prompt the assembly name that is linked to the Page. The name cannot contain a path and an Extension. SRC is used to indicate the source file path to be dynamically compiled and linked to the Page. @Assembly instructions can appear more than once in the main part of the Page. In fact, you need to add instructions separately for each assembly that you want to Link. Name and SRC cannot be used in a @Assembly instruction at the same time, but they can be selected separately for different instructions defined on the Page.

Tip: Although name points to an existing and ready-to-load assembly, the performance difference between name and SRC is minimal. Source files referenced with SRC are compiled only once when the first request is Made. Asp. The NET runtime maps the source file to a dynamically compiled assembly and uses the compiled code until the source file is Changed. That is, after the first call at the application level, the effect on page performance is the same regardless of whether you use name or src.

@Import Instructions

The @Import directive is used to link the specified namespace to the page so that all defined types can be accessed on the page without having to use the fully qualified name (fully qualified name). For example, to create an instance of an ADO dataset class, you can import the System.Data namespace, or you can use the fully qualified name as Follows:

System.Data.DataSet ds = new System.Data.DataSet (); "110"

Once the System.Data namespace is introduced into the current page, we can write the code more naturally as Follows:

DataSet ds = new DataSet ();

The syntax for @Import directives is self-describing:

<%@ Import namespace= "value"%>

@Import can be used more than once in the body of a page. Asp. NET @import directives are equivalent to the using statement of C #, which is also equivalent to visual Basic. Net's Import Statement. Recalling the unmanaged C + + code, It can be said that the directive functions almost the same as the # include Directive.

Note: @Import can only help the compiler resolve the name of the class and does not automatically link the required Assemblies. You can shorten the name of a class by using the @import directive, but if the assembly containing the class is not properly linked, a compiler type error is Thrown. Using fully qualified class name does not help if the assembly is not already linked, because the compiler requires the definition of the Type. You may have noticed that the names of assemblies and namespaces are often consistent. Keep in mind, however, that this is purely coincidental, and that assemblies and namespaces are completely different entities that require corresponding instructions.

For example, to connect a SQL Server database and get some disconnected data, we need to import the following two namespaces:

<%@ Import namespace= ""%>

<%@ Import namespace= "System.Data.SqlClient"%>

We need to namespaces to use datasets and DataTable classes, and to prepare and send commands through the System.Data.SqlClient namespace. In this case, we do not need to link the assembly separately because the System.Data.dll assembly is the default Link.

@Implements Instructions

The @Implements directive is used to indicate the specific interface in The. NET framework that is implemented by the current Page. An interface is a set of logically related function signatures, as a contract for each component to expose its set of Functions. Unlike abstract classes, interfaces do not provide code or perform Functions. If you implement an interface in an asp. net page, define the required methods and properties in the <script> Section. The syntax for the @Implements directive is as follows:

<%@ Implements interface= "interfacename"%> "111"

If you need to implement multiple interfaces in a page, @Implements directives can appear multiple times on that Page. Note that if you decide to define the logic of all pages in a separate file, you cannot use the directive to implement the interface, but in the Code-behind class.

@Reference Instructions

@Reference directives are used to establish dynamic links between the current page and a specified page or user Control. This feature plays a major role in Cross-page Communication. It allows us to create strongly typed instances of the user Control. Let's take a look at its syntax.

@Reference instructions can appear multiple times in a page with two mutually exclusive properties: page and Control. Both of these properties are used to specify the path to the source file:

<%@ Reference page= "source_page"%>

<%@ Reference control= "source_user_control"%>

The page property is used to point to an. ASPX source file, and the control property contains the path to The. ascx user Control. In both cases, the referenced source files are dynamically compiled into the assembly, so that the classes defined in the source file can be used in the active reference page when Programming. At Run time, ASP. NET page is an instance of The. NET Framework class with a specific interface that consists of methods and Properties. When the active reference page executes, the referenced page becomes the class that represents The. aspx source file, which can be instantiated and encoded as Needed. Note that in order for the directive to work, the referenced page must be in a domain with the keynote page. Cross-site calls are not allowed, and the page and control properties only accept relative virtual paths.

Asp. NET page Support instructions

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.