Subscribe

RSS Feed (xml)

Creating Custom Application Settings in the web.config File

The web.config file has a predefined section for application settings, called


appSettings


.This section can be placed in any .config file, and must reside with the


<configuration> section.The following is an example of a simple web.config file:


<configuration>


<appSettings>


<add key="PageSize" value="25" />


</appSettings>


</configuration>


Values can be retrieved using the Configuration API. However, all values are returned as


string types:


Dim pageSize As Integer


pageSize = CType(ConfigurationSettings.ApplicationSettings("PageSize"),


Integer)


Comments


Storing common values within configuration, such as database connection strings, is a


common feature that many applications take advantage of. Requiring developers to


write customer configuration section handlers to store simple values is overkill; hence


the existence of the <appSettings/> section.


Any simple data that you need stored in a central location and that must be available


anywhere within your Web application is a good candidate for the <appSettings/>


section. For other more complicated configuration data structures, you'll probably want


to create a custom configuration section handler.

No comments:

Archives

Variety in the Web World