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>


Ramzanali MominPosted Oct 31, 2018, 1:31 AM
Good One ..
kiquenet kiquenetPosted Sep 28, 2018, 2:56 AM
How get ONLY connecttionstrings from app.config/web.config, NOT machine.config?In the machine.config is a connection string that is called "LocalSqlServer"; the default provider (as expected) is "System.Data.SqlClient", and the connection string is "data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|aspnetdb.mdf;User Instance=true",
Santhakumar MunuswamyPosted Oct 25, 2015, 11:43 AM
Good one
Priyaranjan K SPosted Oct 21, 2015, 1:05 PM
Good One ..
Akash VarshneyPosted Oct 21, 2015, 11:17 AM
really informative .. Nice Explaination
Senthil KiumarPosted Oct 21, 2015, 8:34 AM
Nice Share
Sibeesh VenuPosted Oct 21, 2015, 8:08 AM
Nice Share
Harshad PansuriyaPosted Oct 21, 2015, 7:51 AM
Nice one
Yaduveer SainiPosted Oct 21, 2015, 7:48 AM
Good Job
Nilesh JadavPosted Oct 21, 2015, 6:38 AM
Great good sir !!
Muhammad Aqib ShehzadPosted Oct 21, 2015, 6:06 AM
nice elaboration.