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> 的访问权限。 <appSettings>Web.config文件的节包含键/值对中特定于应用程序的值。

通过分配窗体的表达式来检索应用程序值

<%$ 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)

适用于

另请参阅