Understanding the Structure and Content of Web.Config File
There 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:
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.
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:
to our mailing list and receive new articles Note
: We never rent, trade, or sell my email lists to Visit
.NET Programming Tutorial Homepage ______________________________________________________
to our mailing list and receive new articles
: We never rent, trade, or sell my email lists to
Visit .NET Programming Tutorial Homepage
|How to Define Custom Error Pages for Error Handling In ASP.Net Application| Role of Web gardens and web farms in ASP.NET | Understanding Purpose and Usage of "event" Class Member Modifier in C# (C Sharp) | Understanding the Structure and Content of Web.Config File | Usage of C# (C Sharp) Query Keywords group, by, into | Usage of C# (C Sharp) Query Keywords join, on, equals, let |Usage of C# (C Sharp) Query Keywords orderby, ascending, descending | Usage of C# (C Sharp) Query Keywords select, from, where, in | Usage of Lambda Operator (=>) in C# (C Sharp) |Using C# (C Sharp) as a tool for object oriented programming | Using Dictionaries in .Net An Overview | Using WCF for providing web service |