CompilationMode 枚举

定义

定义指定 ASP.NET 如何编译.aspx页和 .ascx 控件的常量。

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

字段

名称 说明
Auto 0

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

Never 1

不应动态编译页面或控件。

Always 2

应始终编译页面。

示例

下面的示例演示如何使用 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配置节对象标识特定于页面的配置设置。 页面配置节元素可以在配置文件的计算机、站点、应用程序和子目录级别上声明。

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

适用于

另请参阅