CompilationMode CompilationMode CompilationMode CompilationMode Enum

定义

定义一些常量以指定 ASP.NET 应如何编译 .aspx 页和 .ascx 控件。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
继承
CompilationModeCompilationModeCompilationModeCompilationMode

字段

Always Always Always Always 2

应始终编译页面。The page should always be compiled.

Auto Auto Auto Auto 0

如果可能,ASP.NET 将不编译页面。ASP.NET will not compile the page, if possible.

Never Never Never Never 1

在任何情况下都不应动态编译页面或控件。The page or control should never be dynamically compiled.

示例

下面的示例演示如何使用CompilationMode page 指令指示永远不应编译页面。The following 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>

注解

CompilationMode枚举值指示页或控件是否应在运行时编译。The CompilationMode enumeration values indicate whether a page or control should be compiled at run time. 如果未指定编译模式, 则默认值为AlwaysWhen no compilation mode is specified, the default value is Always. 将页设置为从不使用Never特性进行编译会提高性能, 因为在编译过程中 disqualifying 指定的页。Setting a page to never compile using the Never attribute increases performance by disqualifying the specified page in the compilation process. 若要定义特定于CompilationMode页的属性 (该属性指定 .aspx、.ascx 或 master 文件不应在页级编译), 可以使用如下所示的指令:To define a page-specific CompilationMode 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. PagesSection配置节对象标识特定于页的配置设置。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.

如果将设置为Never , 并且页面包含需要编译的脚本块或代码构造, 则 ASP.NET 将返回错误, 并且不会运行页面。 CompilationModeIf the CompilationMode is set to Never and a page contains a script block or code construct that requires compilation, ASP.NET returns with an error and the page doesn't run.

适用于

另请参阅