存储用户应用程序设置、最佳实践和/或建议

发布于 2024-10-07 13:41:56 字数 177 浏览 0 评论 0原文

我的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

独守阴晴ぅ圆缺 2024-10-14 13:41:57

它们是“每个用户”吗?

如果是这样的话,我总是会在数据库中存储这样的东西。

Are they "per user"?

If this is the case, I would always store stuff like this in the database.

心不设防 2024-10-14 13:41:57

在我看来,数据库是存储此类信息的最佳位置。也就是说,最终用户(相对于系统管理员)可以轻松修改并且相对不稳定的信息。您可以轻松地在应用程序级别缓存此信息,以避免一遍又一遍地访问数据库。另请记住,即使您以编程方式更改 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.

海的爱人是光 2024-10-14 13:41:57

您是否使用 ASP.NET 会员资格提供程序?它包括一个“配置文件”部分,可让您存储/检索每个用户的设置。

Are you using the ASP.NET Membership provider? It includes a 'Profile' piece that will let you store/retrieve per user settings.

最单纯的乌龟 2024-10-14 13:41:57

在我看来,web.config 并不是一个好的候选者:

  • 它是应用程序的一部分,所以正如您所说,您的应用程序甚至可能没有写入它的权限。
  • 当您有多个具有不同设置的用户时会发生什么?
  • 如果您的应用程序已签名,则部署后您将无法更改 web.config。

如果您的用户是在数据库中定义的,那么最合乎逻辑的解决方案是将其放在那里。

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.

鹿! 2024-10-14 13:41:57

我认为你必须尝试一下资源文件。

I think you must give a try to resource file.

下雨或天晴 2024-10-14 13:41:56

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

荆棘i 2024-10-14 13:41:56

在我开发的应用程序中,使用了以下区别:

  • Web 服务器上的设置文件:特定于 Web 服务器的设置,而不是特定于它连接的数据库的设置(例如要使用哪个主题、要使用哪个邮件服务器)
  • 数据库表:特定于数据库或当前用户的设置,而不是特定于用户正在使用的客户端计算机的设置(例如使用什么模板发送邮件)
  • Cookies / localstorage:特定于客户端计算机的设置(例如,可移动面板的布局,因为在不同的屏幕上您需要不同的布局)

在所有情况下,都存在一个 API 来抽象读取或写入设置的详细信息。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文