AppSettingsExpressionBuilder 類別

定義

從 Web.config 檔案的 <appSettings> 區段,擷取宣告式運算式中所指定的值。

public ref class AppSettingsExpressionBuilder : System::Web::Compilation::ExpressionBuilder
public class AppSettingsExpressionBuilder : System.Web.Compilation.ExpressionBuilder
type AppSettingsExpressionBuilder = class
    inherit ExpressionBuilder
Public Class AppSettingsExpressionBuilder
Inherits ExpressionBuilder
繼承
AppSettingsExpressionBuilder

範例

下列程式碼範例示範如何在未編譯的頁面中擷取應用程式設定值。

<%@ Page Language="C#" CompilationMode="Never" %>

<!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>Noncompiled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        Welcome to the 
        <asp:Literal ID="Literal1" runat="server" 
        Text="<%$ AppSettings: thisSeason %>" /> Sale!
    </div>
    </form>
</body>
</html>
<%@ Page Language="VB" CompilationMode="Never" %>

<!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>Noncompiled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        Welcome to the 
        <asp:Literal ID="Literal1" runat="server" 
        Text="<%$ AppSettings: thisSeason %>" /> Sale!
    </div>
    </form>
</body>
</html>

此程式碼會從 Web.config 檔案擷取下列運算式。

<configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">

<appSettings>

<add key="thisSeason" value="Fall"/>

</appSettings>

</configuration>

備註

類別 AppSettingsExpressionBuilder 提供Web.config檔案區段中值的 <appSettings> 存取權。 Web.config <appSettings> 檔案的 區段包含索引鍵/值組中的應用程式特定值。

藉由指派表單的運算式來擷取應用程式值

<%$ AppSettings: appSettingsKey %>

至控制項宣告中的屬性。 冒號之前的運算式部分 (:) 會指定要擷取的運算式類型,而冒號之後的部分則表示索引鍵。 上述運算式會從 Web.config 檔案擷取下列值。

<appSettings>

<add key="appSettingsKey" value="appSettingsValue"/>

</appSettings>

當頁面剖析器遇到具有 AppSettings 前置詞的運算式時,它會建立 類別的 AppSettingsExpressionBuilder 實例來處理運算式。

如果在將編譯的頁面中遇到運算式, AppSettingsExpressionBuilder 物件會產生程式碼,以從Web.config檔案擷取指定的值。 此程式碼會在產生的頁面類別執行期間執行。 如果在不會編譯的頁面中遇到運算式,當 AppSettingsExpressionBuilder 剖析和執行頁面時,物件會從Web.config檔案傳回值。

建構函式

AppSettingsExpressionBuilder()

初始化 AppSettingsExpressionBuilder 類別的新執行個體。

屬性

SupportsEvaluate

傳回值,指出是否可在未編譯的頁面中評估運算式。

方法

Equals(Object)

判斷指定的物件是否等於目前的物件。

(繼承來源 Object)
EvaluateExpression(Object, BoundPropertyEntry, Object, ExpressionBuilderContext)

從 Web.config 檔案的 <appSettings> 區段傳回值。

GetAppSetting(String)

從 Web.config 檔案的 <appSettings> 區段傳回值。

GetAppSetting(String, Type, String)

從 Web.config 檔案的 <appSettings> 區段傳回值,並將該值轉換成目標型別。

GetCodeExpression(BoundPropertyEntry, Object, ExpressionBuilderContext)

傳回程式碼運算式,用來在產生的頁面類別中執行屬性指派。

GetHashCode()

做為預設雜湊函式。

(繼承來源 Object)
GetType()

取得目前執行個體的 Type

(繼承來源 Object)
MemberwiseClone()

建立目前 Object 的淺層複製。

(繼承來源 Object)
ParseExpression(String, Type, ExpressionBuilderContext)

在衍生類別中覆寫時,傳回表示剖析的運算式之物件。

(繼承來源 ExpressionBuilder)
ToString()

傳回代表目前物件的字串。

(繼承來源 Object)

適用於

另請參閱