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.

示例

下面的代码示例演示如何使用CompilationModepage 指令指示应永远不会编译页面。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>

注解

CompilationMode枚举值指示是否应在运行时编译的页或控件。The CompilationMode enumeration values indicate whether a page or control should be compiled at run time. 当指定无编译模式下时,默认值将为 Always。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. 若要定义页特定Always不应在页级别编译的特性,指定.aspx、.ascx 或.master 文件,则可以使用类似于以下指令: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. 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.

如果CompilationMode设置为从不页面包含需要编译的脚本块或代码构造,ASP.NET 将返回出现错误和页面将不会运行。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.

适用于

另请参阅