存储用户应用程序设置、最佳实践和/或建议
我的 Web 应用程序中有一些硬编码值需要由用户进行配置,例如电子邮件发送到何处、活动语言以及其他一些属性。 web.config 文件似乎是存储此信息的不错选择,但在部署应用程序时必须处理写入权限有点阻碍我使用 web.config。数据库表可能是另一种解决方案......但感觉有点难看。
存储此信息最合适的位置是什么?
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 to store this info?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
它们是“每个用户”吗?
如果是这样的话,我总是会在数据库中存储这样的东西。
Are they "per user"?
If this is the case, I would always store stuff like this in the database.
在我看来,数据库是存储此类信息的最佳位置。也就是说,最终用户(相对于系统管理员)可以轻松修改并且相对不稳定的信息。您可以轻松地在应用程序级别缓存此信息,以避免一遍又一遍地访问数据库。另请记住,即使您以编程方式更改 web.config 中的值,也会导致应用程序重新启动。不一定是您希望最终用户有权执行的操作。
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.
您是否使用 ASP.NET 会员资格提供程序?它包括一个“配置文件”部分,可让您存储/检索每个用户的设置。
Are you using the ASP.NET Membership provider? It includes a 'Profile' piece that will let you store/retrieve per user settings.
在我看来,web.config 并不是一个好的候选者:
如果您的用户是在数据库中定义的,那么最合乎逻辑的解决方案是将其放在那里。
The web.config does not seem to me like a good candidate:
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.
对于 Web 应用程序,最好的选择是将信息存储在数据库表中。
web.config
用于应用程序的配置设置,而不是用户的配置设置。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.在我开发的应用程序中,使用了以下区别:
在所有情况下,都存在一个 API 来抽象读取或写入设置的详细信息。
In the app I work on, the following distinction is used:
In all cases an API exists that abstracts away the details of reading or writing settings.