Difference between web.config and machine.config?

Each CLR version has a machine.config file, along with an additional web.config file, which I refer to as the "machine level web.config file".

Additionally, as you note, each web application also has a web.config file. Directories inside a web application can also have web.config files too.

Now, the key point is that config files inherit from each other. That means, a web application will read settings defined in the machine.config file and the machine level web.config file (for its given framework version), and its own web.config file.

A common use case for defining things in the machine.config would be to share values between many applications on the server, like a connection string perhaps, or SMTP server settings, things like that.


Those are some of the most important details; although actually, machine.config goes beyond simply configuration for ASP.NET itself. There is another file you should look into, which (I think) is in the same location as machine.config; that is the 'root' web.config, which goes between machine.config and the site-specific web.config files, and is, of course, ASP.NET specific.

Some of the settings you change at the server level in the IIS management console are performed in the root web.config.

Note that this hierarchy is per-.NET version; (2.0 has one; 4.0 has its own)

Another note: You can have sub web.config files in directories and/or sub-applications off a site's root which further modify the 'base'.

Finally, one caveat: Not all settings can be overridden in sub-level web.config files. It is possible (and some are, by default) to lock down certain settings at any level of the hierarchy described here.


Let me clear it out:- in ASP.NET, there is a configuration files hierarchy and machine.config file lies at the root meaning machine.config file contain configuration settings that are applied on each web application, you created. It exists in Windows/Microsoft .NET/Framework/[version]/config You will find a web.config file in the same physical path(I give it name A).This web.config file inherits configuration settings from machine.config.now you have your application folder in which you have web.config(at root level). This web.config( I name it B) inherits configuration settings from A. If you have web.config in application folder's sub-directories than sub-directory web.config inherits configuration settings from B and that is how the ladder goes down


The machine.config is the ultimate master config file on your system with a lot of default settings. When you use web.config files, which is done in a cascading order, you're actually overwriting these settings with new ones.

Tags:

Asp.Net

Iis