Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I've used these two configuration files many times before, but I've never taken the time to fully understand how they really work. As most people do, I understand the basics in how to call WebConfigurationManager.AppSettings["key"] to get config values.

Here are some questions I came up with:

  1. What happens when you reference a configuration value within a class library, and the library is part of a bigger solution? Does the app.config need to be copied to the output directory in order for the variables to be found? (I assume yes)
  2. Can you directly use a configuration value from an app.config in another class library?
  3. Assuming question 3 is "yes", what happens if there are multiple app.config files from different libraries containing configuration values with the same key?
  4. What happens when you reference the web.config, but in a class library?
  5. What happens when you reference the app.config, but in a website or web application project?
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
258 views
Welcome To Ask or Share your Answers For Others

1 Answer

The underlying answer to all of your questions is the same: Unless you set up something unusual, all assemblies in your project will read from the same configuration file. In a web app, they will all read from "web.config". In any other project type, they will read from the starting assembly's config file.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...