CompilationMode CompilationMode CompilationMode CompilationMode Enum

Definition

Defines constants that specify how ASP.NET should compile .aspx pages and .ascx controls.

public enum class CompilationMode
public enum CompilationMode
type CompilationMode = 
Public Enum CompilationMode
Inheritance
CompilationModeCompilationModeCompilationModeCompilationMode

Fields

Always Always Always Always 2

The page should always be compiled.

Auto Auto Auto Auto 0

ASP.NET will not compile the page, if possible.

Never Never Never Never 1

The page or control should never be dynamically compiled.

Examples

The following code example demonstrates how to use the CompilationMode page directive to indicate that a page should never be compiled.

<%@ Page Language="C#" compilationMode="never" %>
<%@ Import namespace="System.IO" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>CompilationMode Example</title>
</head>
<body>
<form id="Form1" runat="server">

Script blocks are not allowed on this page. 
Any server side code that requires compilation 
contained in this page would cause the page to fail
</form>
</body>
</html>
<%@ Page Language="VB" compilationMode="never" %>
<%@ Import namespace="System.IO" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title>CompilationMode Example</title>
</head>
<body>
<form id="Form1" runat="server">
Script blocks are not allowed on this page. 
Any server side code that requires compilation 
contained in this page would cause the page to fail
</form>
</body>
</html>

Remarks

The CompilationMode enumeration values indicate whether a page or control should be compiled at run time. When no compilation mode is specified, the default value is Always. Setting a page to never compile using the Never attribute will increase performance by disqualifying the specified page in the compilation process. To define a page-specific Always attribute that specifies an .aspx, .ascx or .master file should not be compiled at the page level, you can use a directive like the following:

<%@ page compilationMode="never" %>

The compilation mode can also be specified in configuration files. The PagesSection configuration section object identifies page-specific configuration settings. The pages configuration section element can be declared at the machine, site, application, and subdirectory levels of the configuration files.

If the CompilationMode is set to Never and a page contains a script block or code construct that requires compilation, ASP.NET will return with an error and the page will not run.

Applies to

See also