ASP.Net MVC:在哪里存储应用程序和管理面板设置?网络配置?
使用 ASP.NET MVC 为自己构建了一个像样的网站后,我即将为“管理员”角色的用户构建一个“管理面板”来控制网站。具体来说,我构建的网站是企业的内部网站,它由一堆迷你网络应用程序组成,每个应用程序都需要不时进行配置和/或调整。
Web.Config 是存储这些应用程序设置的适当文件吗?
它应该位于单独的 XML 文件中吗?
数据库表(或一组表)?
目前,我没有可用的数据库,但也许以后我会的。目前,我倾向于创建一个 XML 文件并在其中存储值。这是一个合理的做法吗?或者我是否遗漏了一些关于如何执行此操作的明显内容?
编辑: 好的,这是我的抽象层(接口):
public interface IAppSettings
{
IQueryable<string> GetValues(string component, string setting);
void SetValues(string component, string setting, List<string> values, bool append);
}
我想我可以通过这种方式读/写 Web.Config、另一个 XML 或数据库。
你怎么认为?
Having built myself a decent website using ASP.NET MVC, I'm about to build an "Admin Panel" for users in the "Admin" Role to control the website with. Specifically, the website that I've built is an internal site for an enterprise and it consists of a bunch of mini web-apps, each of which need to be configured and/or tweaked from time to time.
Is Web.Config the appropriate file to store these application settings?
Should it be in a separate XML file?
A DB Table (or set of tables)?
Currently, I have no DB available to me, but perhaps at a later date I will. Currently, I'm inclined to create an XML file and store values there. Is this a reasonable approach? Or am I missing something obvious on how to do this?
EDIT: Ok, here's my abstraction layer (Interface):
public interface IAppSettings
{
IQueryable<string> GetValues(string component, string setting);
void SetValues(string component, string setting, List<string> values, bool append);
}
I figure I can read/write to Web.Config, another XML, or a DB this way.
What do you think?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我会推荐你一个数据库。在多用户/多线程应用程序中写入文件可能具有挑战性,如果您不同步对这些文件的访问,则可能会出现问题,更不用说事务访问(如果您需要此类访问)。有一些轻量级的 NoSQL 数据库可能非常有用,并且易于设置。
无论您选择什么,请确保在数据访问层上创建抽象,以便您以后可以轻松切换到另一种方法,例如 SQL 数据库(如果您愿意的话)(尝试过 NoSQL 数据库后您可能不会:-))。
I would recommend you a db. Writing to files in a multi-user/multi-threaded application could be challenging and problems could arise if you don't synchronize the access to those files, not to mention transactional access if you ever needed such. There are some lightweight NoSQL databases which could be extremely useful and easy to setup.
Whatever you choose make sure to create abstractions over the data access layer so that you could easily switch later to another method like a SQL database if you will (after trying a NoSQL database you probably won't will :-)).
这里要问的问题是,一般来说,这是一组会随代码库更改还是由用户更改的设置?如果是前者,XML 就是最佳选择——它可以轻松地通过代码进行版本控制。如果用户要更改它,那么数据库是更好的选择。
The question to ask here is, in general, is this a set of settings that will change with the codebase or be changed by users? If it is the former, XML is the way to go -- it can easily be version controlled with the code. If users are changing it then a database is a better option.