Can anyone provide a quick tutorial on App.config / Web.config?

I used these two configuration files many times before, but I did not find the time to fully understand how they really work. Like most people, I understand the basics of how to call WebConfigurationManager.AppSettings["key"] to get the configuration values.

Here are some questions I came up with:

  • What happens when you refer to a configuration value in a class library and the library is part of a larger solution? Does app.config need to be copied to the output directory to find the variables? (I think yes)
  • Can you directly use the configuration value from app.config in another class library?
  • Assuming question 3 is yes, what happens if there are several app.config files from different libraries containing configuration values โ€‹โ€‹with the same key?
  • What happens when you reference web.config, but in a class library?
  • What happens if you link to app.config but to a website or web application project?
+7
c # application-settings configurationmanager
source share
2 answers

The basic answer to all your questions is the same: if you do not configure something unusual, all assemblies in your project will be read from the same configuration file. In a web application, they will all be read from "web.config". In any other type of project, they will be read from the configuration file of the initial assembly.

+4
source share

The application /web.config is used, which starts the process. Easier if I give an example:

  • Suppose all projects in the solution have an application or web.config.
  • The test in project A calls the code in project B , which calls the web service in project C , which calls the code in project D.

In this case, the code in project A and B will use app.config in project A. The code in project C and D will use web.config in project C.

+4
source share

All Articles