I have a few hardcoded values in my web app that need to be configurable by the user, things like where do emails get sent, active languages, and a few other properties. The web.config file seems like a good candidate to store this information but having to deal with write permissions when the app is deployed kinda holds me back from going with the web.config. A db table could be another solution ... yet it feels kinda ugly.
What would would be the most appropriate place t开发者_运维问答o store this info?
For a web application, your best bet is to store the information in the database table.
The web.config
is meant for configuration settings for the application, not the user.
In the app I work on, the following distinction is used:
- Settings file on web server: settings that are specific to the web server, not to the database it connects with (e.g. which theme to use, which mail server to use)
- Database table: settings that are specific to the database or to the current user, and that are not specific to the client machine the user is working on (e.g. what template to send mails with)
- Cookies / localstorage: settings that are specific to the client machine (e.g. layout of movable panels, because on different screens you want different layout)
In all cases an API exists that abstracts away the details of reading or writing settings.
Are they "per user"?
If this is the case, I would always store stuff like this in the database.
In my opinion, a database is the best place to store this type of information. That is, information that can be easily modified by an end-user (as opposed to a system administrator) and is relatively volatile. You can easily cache this information at the application level to keep from having to hit the database over and over. Also bear in mind that changing values in the web.config, even if you're doing it programmatically, will result in an application restart. Not necessarily something you want your end-users to have the power to do.
Are you using the ASP.NET Membership provider? It includes a 'Profile' piece that will let you store/retrieve per user settings.
The web.config does not seem to me like a good candidate:
- it is part of the application, so as you said, your application may not even have the permissions to write it.
- what happens when you have several users with different settings?
- if your application is signed, you cannot change the web.config once its deployed.
If your user is defined in your DB, then the most logical solution would be to put it there.
I think you must give a try to resource file.
精彩评论