有人可以提供一个快速的App.config / Web.config中教程? [英] Can someone provide a quick App.config/Web.config tutorial?

查看:162
本文介绍了有人可以提供一个快速的App.config / Web.config中教程?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我以前多次使用这两个配置文件,但我从来没有花时间去充分了解他们是如何真正发挥作用。由于大多数人做的,我明白如何调用 WebConfigurationManager.AppSettings [钥匙] 来获取配置的值。


$ B $的基础知识b

这里有一些问题,我想出了:




  1. 当你类库中引用的配置价值会发生什么,以及图书馆是一个更大的解决方案的一部分?是否在app.config需要被复制到输出目录,以便被发现变量? (我认为是)

  2. 可以直接在另一个类库使用配置值从一个app.config?

  3. 假设问题3是是,如果有从包含使用相同的密钥?

  4. 当你引用web.config中会发生什么配置值不同的库多的app.config文件会发生什么,但在一个类库?

  5. 当你引用的app.config会发生什么,但一个网站或web应用程序项目?


解决方案

底层回答你所有的问题都是一样的:除非你设置了一些不寻常的,在你的项目中的所有组件都来自于相同的配置文件中读取。在一个web应用程序,将他们全部来自web.config中读出。在任何其他项目类型,它们会从起点装配的配置文件读取。


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?

解决方案

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.

这篇关于有人可以提供一个快速的App.config / Web.config中教程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆