AppSettingsExpressionBuilder 类
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
从 <appSettings> Web.config 文件的节检索声明性表达式中指定的值。
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
- 继承
示例
下面的代码示例演示如何检索未编译的页面中的应用程序设置值。
<%@ 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) |
从 |
| GetAppSetting(String, Type, String) |
从 Web.config 文件的节中 |
| GetAppSetting(String) |
从 |
| GetCodeExpression(BoundPropertyEntry, Object, ExpressionBuilderContext) |
返回一个代码表达式,该表达式用于在生成的页类中执行属性赋值。 |
| GetHashCode() |
用作默认哈希函数。 (继承自 Object) |
| GetType() |
获取当前实例的 Type。 (继承自 Object) |
| MemberwiseClone() |
创建当前 Object的浅表副本。 (继承自 Object) |
| ParseExpression(String, Type, ExpressionBuilderContext) |
在派生类中重写时,返回一个表示已分析表达式的对象。 (继承自 ExpressionBuilder) |
| ToString() |
返回一个表示当前对象的字符串。 (继承自 Object) |