This documentation is archived and is not being maintained.

AppSettingsExpressionBuilder Class

Retrieves values, as specified in a declarative expression, from the <appSettings> section of the Web.config file.

Namespace:  System.Web.Compilation
Assembly:  System.Web (in System.Web.dll)

[AspNetHostingPermissionAttribute(SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
[AspNetHostingPermissionAttribute(SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)]
public class AppSettingsExpressionBuilder : ExpressionBuilder

The AppSettingsExpressionBuilder class provides access to values in the <appSettings> section of the Web.config file. 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. The preceding expression would retrieve the following value from the Web.config file.


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


When the page parser encounters an expression with the AppSettings prefix, it creates an instance of the AppSettingsExpressionBuilder class to handle the expression.

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. 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.

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" "">

<html xmlns="" >
<head runat="server">
    <title>Noncompiled Page</title>
    <form id="form1" runat="server">
        Welcome to the 
        <asp:Literal ID="Literal1" runat="server" 
        Text="<%$ AppSettings: thisSeason %>" /> Sale!

This code retrieves the following expression from the Web.config file.

<configuration xmlns="">


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




Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0, 2.0