Detailed instructions on ASP. NET page commands

Source: Internet
Author: User
Tags response code

When using commands, although the standard practice is to include commands at the beginning of a file, they can be located anywhere in the. aspx or. ascx file. Each instruction can contain one or more attributes specific to the instruction (in pairs with values ).

Note that the @ page command can only be used in the. aspx file, while the @ control command can only be used in the. ascx file.
The web form page framework supports the following commands.

Common commands in ASP. NET

@ Page defines the page-specific attributes used by ASP. NET page analyzer and compiler. It can only be contained in the. aspx file.
@ Control defines the control-specific attributes used by the ASP. NET page analyzer and compiler. It can only be contained in. ascx files (user controls.
@ Import: explicitly import the namespace to a page or user control.
@ Implements declares the page or user control to implement the specified. NET Framework interface.
@ Register associates aliases with namespaces and class names to allow user controls and custom server controls to be displayed when they are included in the requested page or user control.
@ AssemblyProgramLink to the current page or user control.
@ Outputcache control the page or user control output cache policy in a declared manner.
@ Reference Links a page or user control to the current page or user control in a declarative manner.

ASP. net treats any command block (<% @ %>) that does not contain an explicit command name as the @ page command (for pages) or @ Control Command (for user controls.

@ Page common attributes

Aspcompat
When it is set to true, pages can be executed on a single-threaded unit (STA) thread. This allows pages to call the sta components, such as those developed with Microsoft Visual Basic 6.0. Set this property to true and allow page calls to COM + 1.0 components. This component requires access to the embedded objects of the unmanaged Active Server Pages (ASP. You can access them through the objectcontext object or onstartpage method. The default value is false.
Note that setting this attribute to true may result in poor page performance. For more information, see the remarks section.
Autoeventwireup
Indicates whether the page events are automatically connected to the network. True if event auto-connection is enabled; otherwise, false. The default value is true. For more information, see Web Server Control event model.
Buffer
Determine whether HTTP Response buffering is enabled. True if page buffering is enabled; otherwise, false. The default value is true.
Classname
Specifies the Class Name of the page automatically compiled during the request. This value can be any valid class name, but should not include the namespace.
Clienttarget
Indicates that the ASP. NET Server control should be the target user proxy for the content it presents. This value can be any valid user agent or Alias.
Codebehind
Specifies the name of the compiled file that contains the class associated with the page. This attribute is used by Visual Studio. NET web forms designer. The designer obtains the location of the page class from this attribute to create an instance of the page class for your design. For example, if you create a web form page named webform1 in Visual Studio, the designer will specify the codebehind attribute value as webform1.aspx. VB for Visual Basic, and webform1.aspx. CS for C. This attribute cannot be used at runtime.
CodePage
Indicates the response Code Page value.
Note: If the code page used when creating a web form page is not the default code page on the web server that runs the page, you must set this attribute. The entered value should be the computer code page on which the page is created. For more information about the code page, search for Microsoft developers Network (msdn) at http://microsoft.com/china/msdn.
Compileroptions
A string that contains compiler options for the compilation page. In C # and Visual Basic. net, this is a sequence of compiler command line switches.
Contenttype
Define the HTTP content type of the response as the standard MIME type. Supports any valid HTTP Content string. For a list of possible values, search for mime in msdn on the http://www.microsoft.com/china/technet.
Culture
Regional settings on the page. For more information about the settings and possible cultural values, see the cultureinfo class.
Debug
Indicates whether the page should be compiled using debugging symbols. True if the page should be compiled with a debug symbol; otherwise false.
Description
Provides text descriptions for this page. ASP. NET analyzer ignores this value.
Enablesessionstate
Define the session status requirements for the page. If the session status is enabled, the value is true. If the session status can be read but cannot be changed, the value is readonly. Otherwise, the value is false. The default value is true. These values are case insensitive. For more information, see session status.
Enableviewstate
Indicates whether the view status is maintained for all page requests. If the view status is maintained, the value is true; otherwise, the value is false. The default value is true.
Enableviewstatemac
Indicates that ASP. NET should run the computer authentication check (MAC) on The View status of the page when the page is sent back from the client ). If you want to run Mac check on The View status, the value is true; otherwise, the value is false. The default value is false.
Note that Mac is the encrypted version of the Hidden variable. When a page is sent to a browser, the view status of the page is permanently stored in the variable. When you set this attribute to true, the encrypted view status is checked to verify that it has not been tampered with on the client.
Errorpage
Defines the target URL to be redirected when an unhandled page exception occurs.
Explicit
Determine whether to use visual basic option explicit mode to compile the page. If the value is true, Visual Basic explicit compilation is enabled, and all variables must be declared using dim, private, public, or redim statements; otherwise, the value is false. The default value is false.
Note that this attribute is ignored in all languages except Visual Basic. net. In addition, this option is set to true in the machine. config configuration file. For more information, see computer configuration files.
Inherits
Defines the code hidden class for page inheritance. It can be any class derived from the page class. For information about the code hiding class, see the web form code model.
Language
Specifies the language used for compiling all inline rendering (<%> and <% = %>) and Code declaration blocks on the page. The value can represent any language supported by. net, including Visual Basic, C #, or JScript. net.
Lcid
Defines the region settings identifier of the web form page.
Note that the region settings identifier is a 32-bit value that uniquely defines a region. ASP. NET uses the default region settings of web servers unless you specify different region settings for the web forms page. For more information about region settings, search for msdn that is located on the http://microsoft.com/china/msdn.
Responseencoding
Indicates the response code of the page content. Supports values from the encoding. getencoding method.
SRC
Specifies the name of the source file of the Code hiding class that is dynamically compiled on the request page. You can choose to include the page programming logic in the Code hiding class or the Code declaration block of the. aspx file.
Note that the rad designer (such as Visual Studio. NET) does not use this attribute. Instead, it will pre-compile the code to hide the class and then use the inherits attribute.
Smartnavigation
Indicates whether the page supports smart navigation for Internet Explorer 5.5 or later.
For more information about intelligent navigation, see the remarks section.
Strict
Indicates that the page should be compiled in Visual Basic option strict mode. If option strict is enabled, true is used; otherwise, false is used. The default value is false.
Note that this attribute is ignored in all languages except Visual Basic. net.
Trace
Indicates whether to enable tracking. True if tracing is enabled; otherwise, false. The default value is false. For more information, see ASP. NET tracking.
Tracemode
Indicates how to display trace messages for pages when tracing is enabled. Possible values are sortbytime and sortbycategory. When tracing is enabled, the default value is sortbytime. For more information about tracing, see ASP. NET tracing.
Transaction
Indicates whether transactions are supported on the page. Possible values include disabled, notsupported, supported, required, and requiresnew. The default value is disabled.
Uiculture
Specifies the UI culture settings for the page. Supports any valid UI culture values.
Validaterequest
Indicates whether request verification is required. If true, request verification checks all input data based on the hard-coded list of potentially dangerous values. If a match occurs, the httprequestvalidationexception class is thrown. The default value is true.
This feature is enabled in the computer configuration file (machine. config. You can disable this function by setting this attribute to false in the application configuration file (Web. config) or on the page.

Note that this feature helps reduce the risk of cross-site scripting attacks on simple pages or ASP. NET applications. If the application cannot correctly verify user input, it may be attacked by input in multiple formats, including cross-site scripting and SQL Server directive injection attacks. All forms of input in the application should be carefully evaluated, and they must be correctly verified and encoded, or make sure that the application has exited before processing data or sending the information back to the client. There is no other way to do this.
WarningLevel
Indicates the warning level of the compiler that you want the compiler to abort page compilation. Possible values: 0 to 4

@ Control

Defines the specific attributes of the user control (. ascx file) used by the ASP. NET page analyzer and compiler. This command can only be used for user controls.

Autoeventwireup
Indicates whether the page events are automatically connected to the network. True if event auto-connection is enabled; otherwise, false. The default value is true.
Classname
Specifies the Class Name of the page automatically compiled during the request. This value can be any valid class name, but should not include the namespace.
Compileroptions
A string that contains the compiler options used to compile user controls. In C # and Visual Basic. net, this is a sequence of compiler command line switches.
Debug
Indicates whether the page should be compiled using debugging symbols. True if the page should be compiled with a debug symbol; otherwise false.
Description
Provides text descriptions for this page. Any string description is supported.
Enableviewstate
Indicates whether to maintain the view status of the user control for all page requests. If the view status is maintained, the value is true; otherwise, the value is false. The default value is true.
Explicit
Determine whether to use visual basic option explicit mode to compile the page. True indicates that Visual Basic explicit compilation is enabled, and all variables must be declared using dim, private, public, or redim statements; otherwise, it is false. The default value is false.
Note that this attribute is ignored in all languages except Visual Basic. net. In addition, this option is set to true in the machine. config configuration file. For more information, see computer configuration files.
Inherits
Defines the code hidden classes that are inherited by user controls. It can be any class derived from the usercontrol class. For information about the code hiding class, see the web form code model.
Language
Specifies the language used for compiling all inline rendering (<%> and <% = %>) and server-side script blocks in the user control. The value can represent any language supported by. net, including Visual Basic, C #, or JScript. net.
Strict
Indicates that the page should be compiled in Visual Basic option strict mode. If option strict is enabled, true is used; otherwise, false is used. The default value is false.
Note that this attribute is ignored in all languages except Visual Basic. net.
SRC
Specifies the name of the source file of the Code hiding class to be dynamically compiled when a user control is requested. You can choose to include the page programming logic in the Code hiding class or the Code declaration block of the. ascx file.
Note that the rad designer (such as Visual Studio. NET) does not use this attribute. Instead, it will pre-compile the code to hide the class and then use the inherits attribute.
WarningLevel
Indicates the compiler warning level at which you want the compiler to abort compilation for the user control. The possible values are 0 to 4.

@ Import

Explicitly import the namespace to the page so that all the classes and interfaces of the imported namespace can be used for this page. The imported namespace can be a part of the. NET Framework class library or user-defined namespace.

Namespace
Name of the namespace on the page to import. This can include any namespace or custom namespace contained in. NET Framework.

@ Implements

Shows the current page or user control to implement the specified. NET Framework interface.

Interface
Interface to be implemented in pages or user controls.
<% @ Implements interface = "validinterfacename" %>

@ Register

Associate aliases with namespaces and class names to use concise notation in custom Server Control syntax.

Attribute

Tagprefix
The alias associated with the namespace.
Tagname
The alias associated with the class.
Namespace
The namespace associated with the tagprefix.
SRC
Location (relative or absolute) of the declarative user control file associated with the tagprefix: tagname pair ).
Assembly
The Assembly where the namespace associated with the tagprefix resides.
Note that the Assembly name does not include the file extension.

<% @ Register tagprefix = "tagprefix" namespace = "namespace" assembly = "assembly" %> <% @ register tagprefix = "tagprefix" tagname = "tagname" src = "pathname" %>

@ Assembly

Link the assembly to the current page during compilation so that all classes and interfaces of the Assembly can be used on this page.

Attribute

Name
String that represents the name of the assembly to be linked to the page.
Note that the Assembly name does not include the file extension.
SRC
The path of the source file to be dynamically compiled and linked.
Note that the name and SRC attributes cannot be included in the same @ Assembly command. If you want to use these two attributes, the page must contain multiple commands.
<% @ Assembly name = "assemblyname" %>
<% @ Assembly src = "pathname" %>

@ Outputcache

Control the output cache policies of user controls contained in ASP. NET pages or pages in a declarative manner

Attribute:

Duration
Page or user control cache time (in seconds ). Set this attribute on the page or user control to create an expiration Policy for the HTTP response from the object and automatically cache the page or user control output.
Note that this attribute is required. If this attribute is not included, a analyzer error occurs.
Location
One of the outputcachelocation enumerated values. The default value is any.
The @ outputcache instruction in the user control (. ascx file) does not support this attribute.
Shared
A boolean value to determine whether the output of the user control can be shared by multiple pages. The default value is false. For more information, see the remarks section.
Note that the @ outputcache instruction in the ASP. NET page (. aspx file) does not support this attribute.
Varybycustom
Indicates any text required by the custom output cache. If the value assigned to this attribute is browser, the cache varies with the browser name and major version information. If you enter a custom string, you must overwrite httpapplication. getvarybycustomstring in the global. asax file of the application.
Varybyheader
A semicolon-separated HTTP header list used to change the output cache. When this attribute is set to multiple headers, the output cache contains different versions of a request document for each specified header.
Note: Set the varybyheader attribute to enable cache items in all HTTP 1.1 caches, not limited to ASP. NET caches. The @ outputcache command in the user control does not support this attribute.
Varybyparam
A semicolon-separated string list used to change the output cache. By default, these strings correspond to the query string values sent using the get method attribute, or to parameters sent using the POST method. When this attribute is set to multiple parameters, the output cache contains different versions of the Request Document for each specified parameter. Possible values include none, *, and any valid query string or post parameter names.
Warning this attribute is required when an ASP. NET page is cached. It is also required for user controls, unless the varybycontrol attribute is included in the @ outputcache command of the user control. If it is not included, an analyzer error occurs. If you do not want the cached content to change with any specified parameter, set this value to none. If you want the output cache to change according to all parameter values, set the attribute *.
Varybycontrol
A semicolon-separated string list to modify the output cache of the user control. These strings represent the ID attribute values of the ASP. NET Server Control declared in the user control.
Note that this attribute is required in the user control @ outputcache command unless the varybyparam attribute is already included. The @ outputcache command on the ASP. NET page does not support this attribute.
<% @ Outputcache duration = "100" varybyparam = "NONE" %>

@ Reference

The statement indicates that another user control or page source file should be dynamically compiled and linked Based on the page on which the command is declared.

Attribute
Page
Web form page, ASP. NET should dynamically compile and link the current page according to it at runtime.
Control
User Control, ASP. NET should dynamically compile and link the current page according to it at runtime.
<% @ Reference page | control = "pathtofile" %>

ASP. NET @ command

Orders

For use

Sentence

@ Page

Defines the page-specific (. aspx file) attributes used by ASP. NET page analyzer and Compiler

<% @ Page attribute = "value" [attribute = "value"…] %>

@ Conreol

Defines the specific attributes of the user control (. ascx file) used by the ASP. NET page analyzer and compiler. This command can only be used for User Controls

<% @ Control attribute = "value" [attribute = "value"…] %>

@ Import

Import the namespace to the page so that all the classes and interfaces of the imported namespace can be displayed on this page. The imported namespace can be a. NET Framework class library or a part of the User-Defined namespace.

<% @ Import namespace = "value" %>

@ Implements

Prompt the current page or user control to implement the. NET Framework Interface

<% @ Implements interface = "validinterfacename" %>

@ reference

declarative instructions: dynamically compile and link another user control or page source file based on the page on which the command is declared

<% @ reference page | control =" pathtofile "%>

@ output cache

space ASP.. NET page or user control output cache policy contained in the page

<% @ output cache duration =" # ofseconds "location =" any | client | downstream | Server | none "shared =" true | false "varybycontrol =" controlname" varybycustom = "browser | customstring" varybyheader = "headers" varybyparam = "parametername" %>

@ Assembly

link the assembly to the current page during compilation so that all classes and interfaces of the Assembly can be used on this page

<% @ Assembly name =" assemblyname "%>

<% @ Assembly src =" pathname "%>

@ Register

Associate aliases with namespaces and class names to use concise representations in custom Server Control syntax

<% @ Register tagprefix = "tagprefix" namespace = "namepace" assembly = "assembly" %>
<% @ Register tagprefix = "tagprefix" tagname = "tagname" src = "pathname" %>

 

 

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: info-contact@alibabacloud.com 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.