Sunday, January 13, 2013

An Overview of web.config File in ASP.NET


The web.config file uses a predefined XML format. The entire content of the file is nested in a root <configuration> element. Inside this element are several more subsections, some of which you’ll never change, and others which are more important.

Here’s the basic skeletal structure of the web.config file, with the three most important sections highlighted in bold:

<?xml version="1.0" ?>
<configuration>
<configSections>...</configSections>
<appSettings>...</appSettings>
<connectionStrings>...</connectionStrings>
<system.web>...</system.web>
<system.codedom>...</system.codedom>
<system.webServer>...</system.webServer>
</configuration>

Note that the web.config file is case-sensitive, like all XML documents, and starts every setting with a lowercase letter. This means you cannot write <AppSettings> instead of <appSettings>.

As a web developer, there are three sections in the web.config file that you’ll work with. The <appSettings> section allows you to add your own miscellaneous pieces of information. You’ll learn how to use it in the next section. The <connectionStrings> section allows you to define the connection information for accessing a database. Finally, the <system.web> section holds every ASP.NET setting you’ll need to configure. Inside the <system.web> element are separate elements for each aspect of website configuration. You can include as few or as many of these as you want. For example, if you need to specify special error settings, you would add the <customErrors> element in the <system.web> section. If you wanted to control how ASP.NET’s security works, you’d add the <authentication> and <authorization> sections. 

No comments:
Write comments
Recommended Posts × +