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 指示詞來指出絕不應該編譯頁面。

<%@ 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 傳回錯誤,而且頁面不會執行。

適用於

另請參閱