The syntax for directives in ASP.NET is: Code: <%@ directive_name attribute = value [ attribute = value ] %> Every directive consist of attribute- value pair. There are various application directives supported in ASP.NET. The other directives used with the ASP.NET files are: @Import: It is used for importing the namespace in an application. @Assembly: The assembly is linked to the application at the parse time. In this tutorial, let’s explore all the directives used in ASP.NET. Application Directive The attributes specific to an application are defined using the application directive. They are present in the .aspx files. Syntax for application directive: Code: <%@ Application attribute="value" [ attribute = "value" ] %> The various attributes used by the application are: Language: The code blocks are used inside the language Inherits: The class name from where the code is inherited Description: The explanation of the application. They are not processed by the parsers and compilers. CodeBehind: The source code file containing the application class is defined. Language: The language used for compiling the application is defined. Example: Code: <%@ Application Inherits="MyApp1.object" Description="New App" %> Control Directive It is used for defining the user specific controls used by the compiler and parser. Syntax for control directive: Code: <%@ Control attribute="value" [ attribute = "value" ] %> Some of the attributes used by the control directive are: ClassName: The name of the file used in the control AutoEventWireup: It states the Boolean value used for enabling and disabling the event handlers Description: It states the description of the control page, ignored by the compiler Inherits: The class from where the control page is inherited Explicit: The option explicit mode is used by the user. EnableViewState: It is the Boolean value indicating the view state is maintained across page requests. Strict: The compiler is advised with the strict mode. Language: The code and script language is defined CodeFileBaseClass: The path of the base class and the corresponding code behind class is defined. EnableTheming: The themes used on the control are defined. It is represented by a Boolean value. Src: The path to the source file consisting of the code to be linked to the control. TargetSchema: The name of the schema used for validating the control is defined. Example: Code: <%@ Control Language="C#" EnableViewState="false" %> Assembly Directive The assembly directive is used for linking the application file. The files can be user control, web pages, or a application file. All the assembly classes and interfaces are present. The syntax for the assembly directive is: Code: <%@ Assembly Name="assembly1" %> <%@ Assembly Src="pathname" %> The attributes of the assembly directive are: Src: The path for the source code files to be linked dynamically Name: The assembly name to be linked. Example: Code: <%@ Assembly Name=AssemblyNew" %> <%@ Assembly Src="Demo.cs" %> Import Directive The namespace is imported to the web page using the import directive. The directive specified in the global.aspx file is assigned to the complete application. If it is specified to the specific page, it is applied to that control or page. The syntax for import directive is: Code: <%@ Import Namespace="value" %> The attribute used in the Import directive: namespace: The fully qualified name of the imported namespace. Example: Code: <%@ Import Namespace="System.Net" %> Implements Directive The implements directive states that the page, user control or master page is implemented in specified .NET framework. The syntax for implements directive is: Code: <%@ Implements interface ="interface_name" %> Attributes associated with the implements directive: interface: The interface implemented on the page or user control. MasterType Directive The directive assigns the class name to the Master property of a page. The page is made strongly typed. The syntax for the MasterType directive is: Code: <%@ MasterType attribute="value" [ attribute = "value" ] %> Attributes associated with the MasterType directive are: TypeName: States the name for the master page VirtualPath: The path assigned to the file creating a strong type Master Directive The directive is used to specify the page file as master file. The syntax for the master directive is: Code: <%@ MasterPage Language = "C#" AutoEventWireUp="true" CodeFile="SiteMaster.master.cs" Inherits="SiteMaster" %> Attributes associated with the Master directive are: ClassName: The name of the class associated with the control. CodeFile: The file containing the separate partial class and event handlers associated with it. AutoEventWireup: The simple event handlers used for specifying the life cycle of a web page. Debug: States to compile the master page using the debug symbols. EnableTheming: It shows the look of the master page and controls of the master page Description: A text description is provided to the user. Explicit: The page is compiled using the Option Explicit mode. The value true states that the compile is enabled. Language: The language used for the inline rendering. Code declaration blocks within the page. MasterPageFile: The .master file states the master page. Strict: The page is compiled using the Option Strict mode. Src: The source file name is defined in the code behind class. Example: Code: <%@ Master Language="C#" CodeFile="Master1.master.cs" Inherits="MasterPage" %> Page Directive The page directive defines the attributes for the specific page for the compiler or parser. Syntax for page directive: Code: <%@ Page attribute="value" [ attribute="value" …. ] %> The attributes of the page directive are: Buffer: It is a Boolean value stating the enabling and disabling of the HTTP response buffering. ClassName: It is the name of the class for the page. AutoEventWireup: It states that the page is automatically bound to the methods. Indicated by a Boolean value. CodeFile: The code behind file name ClientTarget: The browser where the controls are rendered by the user. Description: The text value described for the particular page. The parser does not pass the values EnableViewState: The value used for stating the enabled or disabled condition of the view state Error Page: The redirection of the URL if an unhandled exception occurs Language: The programming language for the code to be added TraceMode: It is used for enabling or disabling the tracing values. ValidateRequest: The value stating the input data is validated across all the listed values. Transaction: The transaction supported by the browser is defined. Example: Code: <%@Page Language="C#" EnableViewState="True" Description="Web Page" %> OutputCache Directive The directive controls the output caching capacity of the web page or the control. Syntax for OutputCache directive: Code: <%@ OutputCache Duration="Seconds" Shared="True | False" VarByControl = "controlname" VarByHeader="header" VarByParam = "parameter" CacheProfile="profile name" ProviderName="provider name" Location=" Client | Server | None | ServerAndClient | Any " %> Attributes used in the OutputCache directive are: Duration: The time used by the page is cached. It is defined in seconds. VarByHeader: The list of the HTTP headers used by the output cache. VarByParam: The list used for modifying the output cache. VarByCustom: The custom cache output requirements are stated. Example: Code: <%@ OutputCache Duration="50" VarByParam="None" %> Reference: Directive The reference directive is used for showing that another page or control is compiled to the current page. Syntax for reference directive: Code: <%@ Reference Page="Default.aspx" %> Attributes of the Reference directive are: Page: The external page that needs to be dynamically linked to the current file. virtualpath: It states the reference of the file. Control: The user control used for compiling and linking to the current file. Register Directive It is used for referring the custom control to the tag prefix created by the user. The syntax for the Register directive is: Code: <%@ Register tagprefix="tag1" namespace="namespace" assembly="assembly" %> <%@ Register tagprefix="tag2" tagname="tagname" src="pathname" %> Attributes for the Register directive are: assembly: The assembly where the namespace is associated with the tagprefix attribute. src: The location where the user controls file is associated with the tagprefix:: tagname combination. tagname: The alias associated with the class. tagprefix: The alias providing the shorthand reference to the namespace of the file.