Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Web App Configuration Settings - Best Practices

I was recently involved with patching a web app project and noticed the previous developer used database table for configuration settings instead of web.config (app.settings).

Which should I use? web.config or database table? Which is best?

like image 219
Rob Avatar asked Dec 07 '22 00:12

Rob


1 Answers

Things should go into the web.config in the following situations:

  • They're things that must be available to make the database available (db connection string!)

  • They're things that, if they should change, you want the application pool to refresh, or that are insanely unlikely to change.

  • They're things that need to be available when the database is unavailable for any reason (such as a list of email addresses and an smtp server to send error messages to, or locations where log files belong)

Things should go into the database in the following situations:

  • Both your DB and your web layer use that configuration.

  • You need the ability to change the configuration on the fly, without forcing an application pool refresh.

That said - if you're going to put your config in the database you probably want to cache it in some way in the web layer so you're not hitting the db unnecessarily. I suggest the Cache class for this.

In addition to all of the above, you will also need to consider your company's policy for working with your servers. If its very, very hard for you to work with the db, it might make more sense to put things in the web.config and vice versa.

like image 135
John Christensen Avatar answered Dec 16 '22 11:12

John Christensen