Name
<appSettings>
Synopsis
<appSettings> </appSettings>
The <appSettings>
element can be used to
configure custom application settings as key/value pairs. These
settings can later be retrieved at runtime using the AppSettings
property of the ConfigurationSettings
class, as
shown in the example. This property is shared (static) and does not
require the ConfigurationSettings
class to be
instantiated before accessing the property.
Scope
Any
Attributes
None
Child Elements
-
<add>
The pattern to match.
-
<remove>
The pattern to match.
-
<clear>
The pattern to match.
Example
The following web.config
section
sets an application level key/value pair:
<configuration> <appSettings> <add key="applicationConfigKey" value="bar"/> </appSettings> </configuration>
The following ASP.NET page retrieves the value set by the preceding
code and also retrieves a value set at the machine.config
level:
<%@ Page Language="VB" %> <html> <head> <script runat="server"> Sub Page_Load( ) Message1.Text &= _ ConfigurationSettings.AppSettings("machineConfigKey") Message2.Text &= _ ConfigurationSettings.AppSettings("applicationConfigKey") End Sub </script> </head> <body> <asp:label id="Message1" runat="server">Machine.Config setting: </asp:label> <br/> <asp:label id="Message2" runat="server">Web.Config setting: </asp:label> </body> </html>
Notes
As shown in the example, the <appSettings>
element can be used separately from the
<system.web>
element and its children.
For security reasons, use caution when deciding what kinds of data ...
Get ASP.NET in a Nutshell now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.