The final configuration element is a special one because it allows you to configure your own custom application settings, which can then be easily retrieved from within your ASP.NET applications.
The <appSettings> element allows you to create your own configuration settings as key/value pairs. You can use this configuration element to store configuration information such as DSNs for data access, and then retrieve them in your application using the following syntax:
string DSN DSN = ConfigurationSettings.AppSettings["dsn "];
This is assuming that you’ve stored the DSN using “dsn” as the key.
The <appSettings> element has the following syntax:
<appSettings> <ad key="string value="string" /> <clear /> <remov key="string" /> </appSettings>
Table B-20 describes the <appSettings> element attributes in more detail.
Element |
Attribute |
Description |
---|---|---|
<appSettings> |
Creates key/value pairs that can be retrieved using ConfigurationSettings.AppSettings(key). | |
<add> |
Adds a key/value pair. | |
key |
Specifies the name of the key to use to retrieve the value. | |
value |
Specifies the value to be returned. | |
<clear> |
Removes all key/value pairs added (or inherited) by the current Web.config file. | |
<remove> |
key |
Removes the specified name/value pair added (or inherited) by the current Web.config file. |