CompilationMode 枚举

定义

定义一些常量以指定 ASP.NET 应如何编译 .aspx 页和 .ascx 控件。

public enum class CompilationMode
public enum CompilationMode
type CompilationMode = 
Public Enum CompilationMode
继承
CompilationMode

字段

Always 2

应始终编译页面。

Auto 0

如果可能,ASP.NET 将不编译页面。

Never 1

在任何情况下都不应动态编译页面或控件。

示例

下面的示例演示如何使用 CompilationMode 页面指令指示不应编译页面。

<%@ 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枚举值指示是否应在运行时编译页或控件。 如果未指定编译模式,则默认值为 Always。 通过在编译过程中取消指定页面的资格,将页面设置为永远不会使用 Never 属性进行编译,从而提高性能。 若要定义指定 .aspx、.ascx 或 .master 文件的特定于 CompilationMode 页面的属性不应在页面级别编译,可以使用如下所示的指令:

<%@ page compilationMode="never" %>

还可以在配置文件中指定编译模式。 配置 PagesSection 节对象标识特定于页面的配置设置。 可以在配置文件的计算机、站点、应用程序和子目录级别声明 页面 配置节元素。

如果设置为 Never CompilationMode 页面并且页面包含需要编译的脚本块或代码构造,ASP.NET 返回错误且页面未运行。

适用于

另请参阅