I will let you know why we use it. As you know all are configuration files which are used to store the data which would be key –value.
As per security purpose this data is known as secure data because it cannot be hacked by some external resource directly. So, let's start one by one to know more about these configuration files.
Web.config
It is a configuration file, which is used in web application and it can be an ASP.NET project or MVC project. Some project contains multiple web.config file inside the same project but with different folder. They have their unique benefits. You can create several web.config file in each folder with their unique benefits as per your project requirement.
It is used to store the application level configuration. Sometimes it inherits the setting from the machine.config. It parses at runtime, means if you make any changes then web application will load all the settings in the config file. You don’t need to create a web.config file because it is auto generated when you create a new web application. If you want to create a web.config manually you can create it.
Sample Example
- <?xml version="1.0" encoding="utf-8" ?>
- <configuration>
- <system.web>
-
- </system.web>
- </configuration>
App.config
It is also a special type of configuration file which is basically used with Windows Services, Windows application, Console Apps or it can be WPF application or any others.
It parses at compile time; it means if you edit the app.config when program is running, then you need to restart the application to reload the configuration setting into the program.
When you run the application which contains the app.config, at the time of compilation a copy of app.config with different name moves into build folder for running the application, So that's why we need to restart the program if any changes made in app.config.
It is not added auto when you create a project, to add this you need to go to solution explorer and choose Add New Item and choose “
Application Configuration File”. Windows application always contains the App.config file into the project.
Sample Example
- <?xml version="1.0"?>
- <configuration>
- <connectionStrings>
- <add name="MyKey"
- connectionString="Data Source=localhost;Initial Catalog=ABC;"
- providerName="System.Data.SqlClient"/>
- </connectionStrings>
- </configuration>
Machine.config
It is a special type of configuration file which creates into the OS when you install visual studio. This stores machine level configuration setting. Only one machine.config file exists into the system and it stores highest level of configuration settings.
Machine.config settings apply to all web applications which is residing on the server. The setting of machine.config can be overridden by web.config’s settings. If your system does not contain the machine.config then you cannot execute the application.
Path of Machine.config
32-bit System
%windir%\Microsoft.NET\Framework\[version]\config\machine.config
64-bit System
%windir%\Microsoft.NET\Framework64\[version]\config\machine.config
Sample Example
- <?xml version="1.0" encoding="UTF-8" ?>
- <!--
- Please refer to machine.config.comments for a description and
- the default values of each configuration section.
-
- For a full documentation of the schema please refer to
- http://go.microsoft.com/fwlink/?LinkId=42127
-
- To improve performance, machine.config should contain only those
- settings that differ from their defaults.
- -->
- <configuration>
- <configSections>
- </configSections>
- </configuration>
Thanks for reading the article, Hope you enjoyed.