AppSettingsExpressionBuilder 类

定义

按照声明性表达式指定的设置,从 Web.config 文件的 <appSettings> 节中检索值。Retrieves values, as specified in a declarative expression, from the <appSettings> section of the Web.config file.

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

示例

下面的代码示例演示如何在未编译的页中检索应用程序设置值。The following code example demonstrates how to retrieve an application settings value in a page that is not compiled.

<%@ 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 文件中检索以下表达式。This code retrieves the following expression from the Web.config file.

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

<appSettings>

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

</appSettings>

</configuration>

注解

AppSettingsExpressionBuilder 类提供对 web.config 文件的 <appSettings> 部分中的值的访问。The AppSettingsExpressionBuilder class provides access to values in the <appSettings> section of the Web.config file. Web.config 文件的 <appSettings> 节包含键/值对中特定于应用程序的值。The <appSettings> section of the Web.config file contains application-specific values in key/value pairs.

通过分配窗体的表达式来检索应用程序值An application value is retrieved by assigning an expression of the form

<%$ AppSettings: appSettingsKey %>

控件声明中的属性。to a property in a control declaration. 冒号前面的表达式部分(:)指定要检索的表达式的类型,冒号后面的部分表示密钥。The part of the expression before the colon (:) designates the type of expression to be retrieved, and the part after the colon signifies the key. 前面的表达式将从 web.config 文件中检索以下值。The preceding expression would retrieve the following value from the Web.config file.

<appSettings>

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

</appSettings>

当页分析器遇到带有 AppSettings 前缀的表达式时,它将创建一个 AppSettingsExpressionBuilder 类的实例以处理该表达式。When the page parser encounters an expression with the AppSettings prefix, it creates an instance of the AppSettingsExpressionBuilder class to handle the expression.

如果在要编译的页面中遇到表达式,则 AppSettingsExpressionBuilder 对象将生成代码以从 web.config 文件中检索指定的值。If the expression is encountered in a page that will be compiled, the AppSettingsExpressionBuilder object generates code to retrieve the specified value from the Web.config file. 此代码在生成的页类执行期间执行。This code is executed during the execution of the generated page class. 如果在不进行编译的页面中遇到表达式,则在分析和执行该页时,AppSettingsExpressionBuilder 对象将从 web.config 文件返回值。If the expression is encountered in a page that will not be compiled, the AppSettingsExpressionBuilder object returns the value from the Web.config file when the page is parsed and executed.

构造函数

AppSettingsExpressionBuilder()

初始化 AppSettingsExpressionBuilder 类的新实例。Initializes a new instance of the AppSettingsExpressionBuilder class.

属性

SupportsEvaluate

返回一个值,该值指示是否可在不编译的页中计算表达式。Returns a value indicating whether an expression can be evaluated in a page that is not compiled.

方法

Equals(Object)

确定指定的对象是否等于当前对象。Determines whether the specified object is equal to the current object.

(继承自 Object)
EvaluateExpression(Object, BoundPropertyEntry, Object, ExpressionBuilderContext)

从 Web.config 文件的 <appSettings> 节返回一个值。Returns a value from the <appSettings> section of the Web.config file.

GetAppSetting(String)

从 Web.config 文件的 <appSettings> 节返回一个值。Returns a value from the <appSettings> section of the Web.config file.

GetAppSetting(String, Type, String)

从 Web.config 文件的 <appSettings> 节返回一个值,该值已转换为目标类型。Returns a value from the <appSettings> section of the Web.config file with the value converted to a target type.

GetCodeExpression(BoundPropertyEntry, Object, ExpressionBuilderContext)

返回一个代码表达式,该表达式用于在生成的页类中为属性赋值。Returns a code expression that is used to perform the property assignment in the generated page class.

GetHashCode()

作为默认哈希函数。Serves as the default hash function.

(继承自 Object)
GetType()

获取当前实例的 TypeGets the Type of the current instance.

(继承自 Object)
MemberwiseClone()

创建当前 Object 的浅表副本。Creates a shallow copy of the current Object.

(继承自 Object)
ParseExpression(String, Type, ExpressionBuilderContext)

在派生类中重写时,会返回一个对象,该对象表示通过分析得到的表达式。When overridden in a derived class, returns an object that represents the parsed expression.

(继承自 ExpressionBuilder)
ToString()

返回表示当前对象的字符串。Returns a string that represents the current object.

(继承自 Object)

适用于

另请参阅