Ask Learn
Preview
Please sign in to use this experience.
Sign inThis browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Defines page-specific (.aspx file) attributes used by the ASP.NET page parser and compiler.
<%@ Page attribute="value" [attribute="value"...] %>
Async
Makes the page an asynchronous handler (that is, it causes the page to use an implementation of IHttpAsyncHandler to process requests).
The default is false.
AsyncTimeOut
Defines the time-out interval (in seconds) used when processing asynchronous tasks. The default is 45 seconds.
The value must be an integer.
AspCompat
When set to true, allows the page to be executed on a single-threaded apartment (STA) thread. This allows the page to call STA components, such as a component developed with Microsoft Visual Basic 6.0. Setting this attribute to true also allows the page to call COM+ version 1.0 components that require access to unmanaged Active Server Pages (ASP) built-in objects. These are accessible through the ObjectContext object or the OnStartPage method. The default is false.
Note
Setting this attribute to true can cause your page's performance to degrade. For more information, see the Remarks section.
Buffer
Determines whether HTTP response buffering is enabled. true if page buffering is enabled; otherwise, false.
The default is true.
ClassName
A string that specifies the name of the page class that will be dynamically compiled when the page is requested. This value can be any valid class name and can include a fully qualified class name. If a value for this attribute is not specified, the class name for the compiled page is based on the page's file name and uses the default namespace ASP. If a value for the ClassName attribute is specified without a full namespace, then the namespace ASP is used, combined with the specified class name to create a fully qualified class name.
Another page can reference the class name assigned to the first page by using the @ Reference directive.
Note
It is possible in the code-behind page class to reference members of the associated .aspx page class using the fully qualified class name for the .aspx page. However, if you precompile your site with source protection enabled, the code-behind page class is not located in the same assembly as the .aspx page class. Therefore the class reference in the code-behind file will not work. For more information on precompilation, see ASP.NET Web Site Precompilation Overview.
CodeBehind
Specifies the name of the compiled file that contains the class associated with the page. This attribute is not used at run time.
Note
This attribute is included for compatibility with previous versions of ASP.NET, to implement the code-behind feature. In ASP.NET version 2.0, you should instead use the CodeFile attribute to specify the name of the source file, along with the Inherits attribute to specify the fully qualified name of the class.
EnableEventValidation
Enables validation of events in postback and callback scenarios. true if events are being validated; otherwise, false. The default is true.
Page event validation reduces the risk of unauthorized postback requests and callbacks. When the enableEventValidation property is set to true, ASP.NET allows only the events that can be raised on the control during a postback request or callback. With this model, a control registers its events during rendering and then validates the events during the post-back or callback handling. All event-driven controls in ASP.NET use this feature by default.
It is strongly recommended that you do not disable event validation. Before disabling event validation, you should be sure that no postback could be constructed that would have an unintended effect on your application.
EnableViewStateMac
Indicates that ASP.NET should run a machine authentication check (MAC) on the page's view state when the page is posted back from the client. true if view state should be MAC checked; otherwise, false. The default is true.
Note
A view-state MAC is an encrypted version of the hidden variable that a page's view state is persisted to when sent to the browser. When you set this attribute to true, the encrypted view state is checked to verify that it has not been tampered with on the client. Note that setting this attribute to true affects performance, because the variable value must be decrypted and encrypted for each round trip of the page.
Explicit
Determines whether the page is compiled using the Visual Basic Option Explicit mode. true indicates that the Visual Basic explicit compile option is enabled and that all variables must be declared using a Dim, Private, Public, or ReDim statement; otherwise, false. The default is false.
Note
This attribute is ignored by languages other than Visual Basic. Also, this option is set to true in the Machine.config configuration file. For more information, see Machine Configuration Files.
Inherits
Defines a code-behind class for the page to inherit. This can be any class derived from the Page class. This attribute is used with the CodeFile attribute, which contains the path to the source file for the code-behind class. The Inherits attribute is case-sensitive when using C# as the page language, and case-insensitive when using Visual Basic as the page language.
If the Inherits attribute does not contain a namespace, ASP.NET checks whether the ClassName attribute contains a namespace. If so, ASP.NET attempts to load the class referenced in the Inherits attribute using the namespace of the ClassName attribute. (This assumes that the Inherits attribute and the ClassName attribute both use the same namespace.)
For more information about code-behind classes, see ASP.NET Web Page Code Model.
LCID
Defines the locale identifier for the Web Forms page.
Note
The locale identifier is a 32-bit value that uniquely defines a locale. ASP.NET uses the default locale of the Web server unless you specify a different locale for a Web Forms page by using this attribute. Note that the LCID and Culture attributes are mutually exclusive; if you use one of these attributes, you cannot use the other in the same page. For more information about locales, search the MSDN Library.
MaintainScrollPositionOnPostback
Indicates whether to return the user to the same position in the client browser after postback. true if users should be returned to the same position; otherwise, false. The default is false.
Note
Developers can define this attribute for all pages by setting the maintainScrollPostitionOnPostback attribute (note that it is case-sensitive in configuration files) on the <pages> element of the Web.config file.
SmartNavigation
Indicates whether the page supports the smart navigation feature of Internet Explorer 5.5 or later. true if smart navigation is enabled; otherwise, false. The default is false.
You can also set the SmartNavigation property for the page in code, but in general you should set it using the attribute with the @ Page directive. For more information about how this feature improves the user experience of navigating on Web pages, see the SmartNavigation property.
Src
Specifies a path to a source file containing code that is linked to the page. In the linked source file, you can choose to include programming logic for your page either in a class or in code declaration blocks.
You can use the Src attribute to link build providers to the page. For more information, see the BuildProvider class. Also, in versions of ASP.NET prior to 2.0, the Src attribute was used as an alternative way to link a code-behind file to a page. In ASP.NET 2.0, the preferred approach to linking a code-behind source file to a page is to use the Inherits attribute to specify a class, along with the CodeFile attribute to specify the path to the source file for the class.
Strict
Indicates that the page should be compiled using the Visual Basic Option Strict mode. true if Option Strict is enabled; otherwise, false. The default is false.
Note
This attribute is ignored by languages other than Visual Basic.
ValidateRequest
Indicates whether request validation should occur. If true, request validation checks all input data against a hard-coded list of potentially dangerous values. If a match occurs, an HttpRequestValidationException exception is thrown. The default is true.
This feature is enabled in the machine configuration file (Machine.config). You can disable it in your application configuration file (Web.config) or on the page by setting this attribute to false.
Note
This functionality helps reduce the risk of cross-site scripting attacks for straightforward pages and ASP.NET applications. An application that does not properly validate user input can suffer from many types of malformed input attacks, including cross-site scripting and Microsoft SQL Server injection attacks. There is no substitute for carefully evaluating all forms of input in an application and making sure that they are either properly validated or encoded, or that the application is escaped prior to manipulating data or sending information back to the client.
This directive can be used only in Web Forms pages. You can include only one @ Page directive per .aspx file. Further, you can define only one Language attribute per @ Page directive, because only one language can be used per page. Because the most commonly used default values are supplied for most of the attributes, either in the source code or in configuration files, it is often unnecessary to add a large set of attributes to the directive. Generally, you should add the minimal set of attributes required to specify the features you want for a page. If there is a common attribute that you want to apply to all pages, for example if you want to enable tracing on all pages, consider enabling the feature in the Web.config file rather than adding the Trace attribute to every individual page.
Note
The @ Page directive has a number of attributes in common with other directives that apply to an entire source file, such as the @ Control directive (used in .ascx files for Web user controls) and the @ Master directive (used in .master files for master pages).
To define multiple attributes for the @ Page directive, separate each attribute/value pair with a single space. For a specific attribute, do not include a space on either side of the equal sign (=) that connects the attribute with its value. For an example, see the Example section of this topic.
Smart navigation is an ASP.NET feature supported in Internet Explorer 5.5 and later browsers. It allows a page to be refreshed while maintaining scroll position and element focus between navigations, causing only a single page to be stored in the browser's history, and without the common flicker associated with refreshing a Web page. Smart navigation is best used with ASP.NET pages that require frequent postbacks but with visual content that does not change dramatically on return. Consider this carefully when deciding whether to set this attribute to true.
When the AspCompat attribute is set to true for a page, if you use a constructor to create a COM component before the request is scheduled, it will run on a multithreaded apartment (MTA) thread. Doing this causes significant Web server performance degradation. To avoid this problem, create COM components only from within one of the Page events (such as Page_Load, Page_Init, and so on) or one of the Page methods. Be sure as well that the objects are not created at page construction time.
The following code example demonstrates the recommended way to create an instance of a COM object in a page with AspCompat enabled.
<%@ Page AspCompat="true" language="C#" %>
<script runat="server" >
MyComObject comObj;
public void Page_Load(){
// Use comObj here when the code is running on the STA thread pool.
comObj = New MyComObject();
// Do something with the combObj object.
}
<%@ Page AspCompat="true" language="VB" %>
<script runat="server" >
Dim comObj As MyComObject
Public Sub Page_Load()
'Use comObj here when the code is running on the STA thread pool.
comObj = New MyComObject()
' Do something with the combObj object.
End Sub
</script>
Note
Adding an @ Master directive to a master page does not allow you to use the same directive declaration in pages that depend on the master. Instead, use the <pages> element to define page directives globally.
The following code example instructs the ASP.NET page compiler to use Visual Basic as the server-side code language for the page, and sets the default HTTP MIME ContentType attribute transmitted to the client to "text/xml"
.
<%@ Page Language="VB" ContentType="text/xml" %>
Please sign in to use this experience.
Sign in