luppi
luppi

Reputation: 301

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?
Or creating some DAL and BLL clases that work with database?

Upvotes: 10

Views: 4764

Answers (5)

Pent Ploompuu
Pent Ploompuu

Reputation: 5414

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
  2. Server instance specific configuration (SQL connection strings, local file paths) - in web.config
  3. Application (database) configuration (feature selection and other global application settings that change rarely, if ever) - in database but without an UI
  4. Application configuration - in database, accessible through an admin UI

Upvotes: 9

ChrisF
ChrisF

Reputation: 137188

To actually answer the question:

Basic information is going to have to be stored locally in web.config (connection strings etc.)

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.

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.

Upvotes: 3

Sky Sanders
Sky Sanders

Reputation: 37104

Build a configuration section. It is pretty straight forward and suits your needs.

Upvotes: 0

Rudi
Rudi

Reputation: 3228

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. 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.

Upvotes: 5

m3kh
m3kh

Reputation: 7941

In most times, you have separate settings for each module on each page. Thus, you have to save them in database.

Upvotes: 0

Related Questions