Web.Config Written on: Nov, 16th 2001.
Application("DSN") = "Server=moon; Driver=Sql Server; Database=Store; UID=user; PWD=bingo;"
Above declaration in the global.asa file might be familiar to almost all ASP programmers.
While going through the MSDN, I was overwhelmed, by looking into the web.config file which handles all configuration for an application. The replacement for the above declaration in ASP .NET is as follows:
<configuration>
<appSettings>
<add key="DSN" value="Server=moon;database=Store;Trusted_Connection=yes" />
</appSettings>
</configuration>
Then, in your ASPX page, you should have the following statement to retrieve the value for DSN.
Dim dsn As String = ConfigurationSettings.AppSettings("DSN")
So, I started to ask the following questions to myself.
What exactly is web.config?
Does this handles only the above example?
What are the benefits of web.config?
And, following were the results for my questions, and I would like to share with you all. This is based on Beta2
Introduction
Well, web.config is a XML-based configuration file. If you see the above example, you can make sure that all the elements are based on XML standards. Obviously, we can develop a tool for modifying and editing this configuration file.
A web.config can appear in any directory on an ASP.NET Web application server. Said this, if you have a web.config file in the directory "c:\inetpub\wwwroot", then the settings specified in the web.config is applicable to all the subdirectories under wwwroot. Each sub-directory can have its own web.config file and it will overwrite the settings of the web.config file in the parent directory.
There is another file called machine.config, which provides configuration settings for the entire server. If you change the contents of any web.config file then the change will be immediately reflected in the processing of any incoming requests to the web' server. These settings are calculated only once and then cached across subsequent requests. ASP.NET automatically watches for file changes and will invalidate the cache if any of the configuration files change. (For more information on caching Click here)
The root element of a web.config file is always a <configuration> tag. The <configuration> tag contains three different types of elements: 1) configuration section handler declarations, 2) configuration section groups, and 3) configuration section settings.
Following are the list of commonly used Configuation tags, that, we be used in our web applications and will go thru them
1) Appsettings
2) Authentication
3) Authorization
4) Compilation
5) CustomErrors
6) Globalization
7) Identity
8) MachineKey
9) Pages
10) ProcessModel
11) SessionState
12) Trace
<appSettings>
This can be declared at the machine, site, application and subdirectory level Include all the custom settings for your application in this section. Appsettings tag contains two attributes viz; key and value.
<add key="key" value="value"/>
Eg: <add key="DSN" value="Server=moon;database=Store;Trusted_Connection=yes" />
<authentication>
All the authentication/security related stuff are declared in this section. Authentication section contains a single attribute called "mode". Possible values for "mode" are (a) Forms (b) None (c) Passport and (d) Windows
Form based authentication can be used, if you want to use ASP .NET forms-based authentication.
If you want to allow anyonmyous users to access your website, select none.
Passpost authenticatio