Setting and Retrieving Custom Application Settings


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.

<appSettings>

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:

Dim DSN As String 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> <add key="string" value="string" /> <clear /> <remove key="string" /> </appSettings> 

Table B-20 describes the <appSettings> element attributes in more detail.

Table B-20: <appSettings> Element Attributes

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.




Microsoft ASP. NET Programming with Microsoft Visual Basic. NET Version 2003 Step by Step
Microsoft ASP.NET Programming with Microsoft Visual Basic .NET Version 2003 Step By Step
ISBN: 0735619344
EAN: 2147483647
Year: 2005
Pages: 126

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net