在 Asp.Net 中拥有实时可读配置文件的最佳方法
我需要调整一些变量(仅在开发设置中),而无需重新启动 IIS 或任何其他内容(因此我认为 Web.Config 是放置它们的错误位置)。 哪里是最容易放置大约 500 个配置设置的位置,这些设置必须在 IIS 运行时为每个请求读取并写入(就像我所说的那样)?
编辑:就像我说的,这只是为了一些 Q&D 开发,所以我不关心任何方面的性能。 数据库有点矫枉过正(而且可能比我想要处理的工作更多),我想要一些快速的东西(比如设置),我不必担心解析并且可以读取和写入。 如果我使用 XML,我应该将文件写入哪里,这样我就不必花时间处理权限问题了?
I need to tweak some variables (only in a development setting) without having to restart IIS or anything (so I assume Web.Config is the wrong place to put them). Where is the easiest place to put about 500 config settings that have to be read for every request and written to, like I said, while IIS is running?
EDIT: Like I said, this is only for some Q&D development so I don't care about performance in any way. A database is a bit of overkill (and is probably more work than I want to deal with), I want something fast (like Settings), that I don't have to worry about parsing and can read from and write to. If I do XML, where do I write the file to so I don't have to spend time messing around with permissions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
在数据库中?
In a database?
每个请求都要读取 500 个配置设置? 我将它们放入数据库中,以便可以对它们进行索引和缓存。 单独的 XML 或数据文件也很可能由 Web 服务器缓存在内存中,但仍然无法提供索引数据库表所能提供的性能。 但这取决于您访问设置的方式。
500 Config Settings to be read for every request? I'd put them in a database so they can be indexed and cached. A separate XML or data file would also most likely be cached in memory by the web server, but still wouldn't provide the performance an indexed database table could. But it depends on how you are accessing the settings.
您可以制作自己的“配置”文件。 只是不要将其命名为.config。 然后您可以像读取文本文件一样读取它并设置所有属性。 只需实现您自己的文件监视类或了解文件已更改的内容,以便您可以更新代码。
You can just make your own "config" file. Just don't name it .config. Then you can read it just like a text file and set all your properties. Just have to either implement your own file monitoring class or something to know the file has changed so you can update your code.
有了这么多的配置选项,数据库系统加上一些经过深思熟虑的缓存很可能是最好的主意!
您还必须确保考虑加载/存储它们对所有请求的影响,即使值很小,这也可能是很大的开销。 所以缓存将非常重要。
With that many configuration options a database system, with some well thought caching is going to most likely be the best idea overall!
You have to be sure to consider the impacts of loading/storing them on all requests as well, as even with small sized values, that can be a big amount of overhead. SO caching is going to be very important.
我知道您说过您不需要数据库,但有 500 个设置,这似乎是最好的解决方案。
也就是说,如果您确实不需要数据库,您可以随时将它们转储到本地存储的 xml 文件中,并在需要时进行读/写。
I know you said you don't want a database, but with 500 settings, it just seems like the best solution.
That said, if you really don't want a database, you could always dump them into an xml file stored locally and just read/write when needed.