What is the difference between app.config, web.config and machine.config ?

web.config is used with web applications. web.config will by default have several configurations required for the web application. You can have a web.config for each folder under your web application.

app.config is used for windows applications. When you build the application in vs.net, it will be automatically renamed to <appname>.exe.config and this file has to be delivered along with your application.

You can use the same method to call the appsettings values from both config files :

System.Configuration.COnfigurationSettings.AppSettings["Key"]

When I add a connection string by wizard in a WebApp , the wizard add the
connection string to web.config like
<add name="MyDataBase" connectionString="Data Source=.\SQLEXPRESS;Initial
Catalog=xxxx;.....

But if I add the same connection string by wizard in a class library
project, the connection string in app.config will be:
<add name="dataHealth.Properties.Settings.MyDataBase"
connectionString="Data Source=.\SLEEPERS;Initial Catalog=xxxx...

The connection string name in app.config will be initial with
"ProjectName..Properties.Settings"
Why have the difference between web.config and app.config

hi...
app config-->This app settings is used for windows based application,suppose if you are creating windows based application in vb.net you have to set the database setting in app settings
web.config-->This web settings is used for web based application,suppose if you are creating web based application in asp.net you have to set the database setting in wen settings

Don't forget that the machine.config file exists, which is your global config for .NET, most commonly referenced in ASP.NET literature, as the global settings used in IIS for ALL ASP.NET apps on that server. The only time you ever really want to alter this file is if your running on a custom web server and want to change your global .NET settings. Messing with this file is a very BAD idea.

Also, App.Config in an application is optional, it doesn't have to be used when writing desktop apps.

Web.Config is required for ASP.NET webpages

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.