asp.net.ph

Skip Navigation Links

<appSettings> add Element

ASP.NET Syntax   ASP.NET Configuration Sections


Adds a custom application setting as a name/value pair to the collection of application settings.

<add
   key = "String name"
   value="String value"
/>

Attributes and Elements

The following sections describe attributes, child elements, and parent elements.

Attributes


Attribute Description
key Required String attribute.

Specifies the name of the application setting. This attribute is the collection key.

value Required String attribute.

Specifies the value of the application setting.

Inherited attributes Optional attributes.

Attributes that are inherited by all section elements. For more information, see Shared Configuration Attributes.


Child Elements

None.

Parent Elements


Element Description
configuration Specifies the required root element in every configuration file that is used by the common language runtime and the .NET Framework applications.
system.web Specifies the root element for the ASP.NET configuration settings in a configuration file and contains configuration elements that configure ASP.NET Web applications and control how the applications behave.
appSettings Contains custom application settings, such as file paths, XML Web service URLs, or any information that is stored in the .ini file for an application.

Remarks

The add element adds a custom application setting as a name/value pair to the collection of inherited application settings in the appSettings element.

The appSettings element stores custom application configuration information such as file paths, XML Web service URLs, or any information that is stored in the .ini file for an application. The key/value pairs that are specified in the appSettings element can be accessed in code using the ConfigurationSettings class.

Default Configuration

The following default appSettings element is configured in the Machine.config file in the .NET Framework versions 1.0 and 1.1.

<appSettings>
   <add key = "XML File Name" 
      value="myXmlFileName.xml" />
</appSettings>

Example

Configuration files that are specified in a file attribute must have appSettings rather than configuration as the root node. The following code is correct for a configuration file that is specified in the file attribute.

<?xml version = "1.0" encoding = "utf-8" ?>
<appSettings>
   <add key = "Application1" value="MyApplication1" />
   <add key = "Setting1" value="MySetting" />
</appSettings>

The following code example shows how to define a custom application setting in a configuration file.

<configuration>
   <appSettings>
      <add key = "Application Name" value="MyApplication" />
   </appSettings>
</configuration>
See Also

<appSettings> Section   <appSettings> clear Element   <appSettings> remove Element



© 2025 Reynald Nuñez and asp.net.ph. All rights reserved.

If you have any question, comment or suggestion
about this site, please send us a note