I have an ASP.NET application and need to store some settings.
The settings are, among other things, titles on pages shown in my application. The titles are changed on a regular basis (every week or so) and I’m wondering on how to do this the smart way:
-
Save the settings in the
web.config(slow read time, and application has to be restarted to detect changes). -
Save the settings in a database.
-
My own XML file (such as a custom configuration section in its own XML file).
I’m looking for anything that could point me in a better direction.
What would you do?
I would use a database.
As others have said,
web.configis really meant for application-level settings only.One issue with an XML file is that if you ever decide to move to a load-balanced scenario, then you have to worry about how to replicate that file from one server to another. It’s considered a best practice from a scalability and security perspective to not have any application dynamic data in the filesystem at the web tier (if you want to be able to update the file, it means you would have to allow your web app to have write access to the local filesystem, which is a security risk).
Putting it in the DB allows you to read it once when your app first starts. You can then cache all or part of it in memory with a SqlDependency or SqlCacheDependency, so that the code receives a notification if the DB table changes (you can do something similar with an XML file, if you must).
With the info in the DB, you can more easily add a load balanced server later, if you need to, and your web app can stay read-only.