CODE SAMPLE - web.config - How to acquire Name/Value pair data!
web.config is a great place to store data on an Intranet
especially if the data changes frequently and attacks by hackers are not
a major concern (I guess that is always a major concern). Anyhow, it
can be a useful place to store connection strings, stored procedure
names, values for any purpose, parameters, etc. Here I simply show how
to fetch the data from web.config. C# code only.
web.config Data Sample :
<add key="JobCfgTitleMaster" value="BBS System version 1.1"/>
Namespace(s) Required:
using System.Configuration;
Code to Access: (deprecated - see below for newer technique)
private static readonly string strJobCfgTitleMaster =
ConfigurationSettings.AppSettings["JobCfgTitleMaster"];
Notes:
A static readonly variable is used as it will be the same for all instances.
Code to Access:(newer technique)
private static readonly string strJobCfgTitleMaster =
ConfigurationManager.AppSettings["JobCfgTitleMaster"];