
Understanding the Structure and Content of Web.Config FileThere are many configuration settings that you require for your application. For example, mode of authentication you use or the database connection for your application. Instead of recording such configuration details in every page or at a static class, what if you have a single file in which you can store all configuration settings and use those settings across your application? You can achieve this using the configuration file named web.config file.
Structure
of web.config file: Web.config
file is structured using XML. The file contains tags and each tag can
have sub-tags and attributes associated with it. Here is a sample web.config
file with basic configuration settings done: <?xml
version=1.0 encoding=utf-8?> <system.net> <system.web>
<sampleCustomTag
> As shown
in the example above, web.config file has its root element as <configuration>
tag. Inside this root element, following sections are allowed: configSections:
If you want to create and use any custom tags in your web.config file,
then you can define those custom tags using <section> tag inside
<configSections>. In the above example, you have defined a custom
tag called sampleCustomTag and that is used at the end of your web.config
file as shown above. <sampleCustomTag> can define as many key value
pairs that are required. system.net:
If you have any network classes then the configuration settings for those
classes can be done using system.net. o compilation:
Using this tag you can specify what language you have used for coding
and whether debugging has to be enabled in your application or not. This
information will be used at the time of compilation. When debugging is
set to true, performance of your application will be low. appSettings:
If you need specific data throughout the application, then you can define
them as key value pair inside <appSettings> tag. You have defined
a database connection string in <appSettings> tag above. You can
access this connection string in your page using the following line of
code: string sampleConnString
= (string )ConfigurationSettings.AppSettings["DBConnString"]; Customized
tags: Customized tags defined in configSections can be specified as an
independent tag. For example, <sampleCustomTag> is a custom tag
defined and used in web.config file shown above. The key sampleKey
mentioned inside this custom tag can be accessed using the following line
of code: ConfigurationSettings.GetConfig("sampleCustomTag")("sampleKey")
_______________________________________________________________________
FREE
Subscription
Subscribe
to our mailing list and receive new articles Note
: We never rent, trade, or sell my email lists to Visit
.NET Programming Tutorial Homepage ______________________________________________________ |