简体   繁体   English

在web.config或数据库中存储配置设置

[英]Storing configuration settings in web.config or database

What it best location to store various configuration settings of a web site modules. 存储网站模块的各种配置设置的最佳位置。

Creating class (that inherit ConfigurationSection) that map the settings in web.config file? 创建映射web.config文件中的设置的类(继承ConfigurationSection)?
Or creating some DAL and BLL clases that work with database? 或者创建一些与数据库一起使用的DAL和BLL分支?

I've used a simple heuristic to categorize each configuration variable into one of four categories: 我使用了一个简单的启发式方法将每个配置变量分类为以下四种类别之一:

  1. Compile time configuration (changes done together with code changes) - if possible then inside the code or assembly (as an embedded resource), otherwise in web.config 编译时间配置(与代码更改一起完成的更改) - 如果可能,然后在代码或程序集内部(作为嵌入式资源),否则在web.config中
  2. Server instance specific configuration (SQL connection strings, local file paths) - in web.config 特定于服务器实例的配置(SQL连接字符串,本地文件路径) - 在web.config中
  3. Application (database) configuration (feature selection and other global application settings that change rarely, if ever) - in database but without an UI 应用程序(数据库)配置(功能选择和其他全局应用程序设置很少变化,如果有的话) - 在数据库中但没有UI
  4. Application configuration - in database, accessible through an admin UI 应用程序配置 - 在数据库中,可通过管理UI访问

Storing the configuration settings in the Web.config will have the effect that if you modify the web.config file, your application will be restarted and the new settings will have immediate effect. 在Web.config中存储配置设置将产生这样的效果:如果您修改web.config文件,您的应用程序将重新启动,新设置将立即生效。 If you are running the application on multiple machines, you however will need to update each machine. 如果您在多台计算机上运行该应用程序,则需要更新每台计算机。

If you store the configuration settings in the database, you will need to either restart your web application manually or have a function (such as an admin page/site) to allow the application to re-read the settings. 如果将配置设置存储在数据库中,则需要手动重新启动Web应用程序或使用某个功能(例如管理页面/站点)以允许应用程序重新读取设置。

To actually answer the question: 要真正回答这个问题:

Basic information is going to have to be stored locally in web.config (connection strings etc.) 基本信息必须本地存储在web.config(连接字符串等)中

Beyond that other information could be stored in either location. 除此之外,其他信息可以存储在任一位置。

Having it in the database means that it's easier to write admin pages to control the information rather than editing the web.config file directly. 将它放在数据库中意味着编写管理页面来控制信息比直接编辑web.config文件更容易。

How often are things going to change? 事情经常发生变化? If set up is a one-off thing then having admin pages would be overkill, but if there's ongoing changes (adding new users, categories etc.) then they might be a good idea. 如果设置是一次性的事情,那么拥有管理页面将是过度杀伤,但如果有持续的变化(添加新的用户,类别等),那么他们可能是个好主意。

Also with data in the database you can perform remote administration on the system 还可以使用数据库中的数据在系统上执行远程管理

So, without more information on your application I can't make a recommendation. 因此,如果没有关于您的应用程序的更多信息,我无法提出建议。

In most times, you have separate settings for each module on each page. 在大多数情况下,每个页面上的每个模块都有单独的设置。 Thus, you have to save them in database. 因此,您必须将它们保存在数据库中。

Build a configuration section. 构建配置部分。 It is pretty straight forward and suits your needs. 它很直接,适合您的需求。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM