实际上,我正在使用 xml 文件进行网页配置,xml 文件包含所有内容,所有控件/内容都是通过这些 XML 文件加载的,并且它可以工作,这些配置文件可以动态更改,而网页只需更改其布局/内容不需要重新编译/重新部署,我必须保持这种做事方式。
问题是我每页加载这些文件 20 次,当我想从我的类/ashx 文件访问它们时,我只是不断打开它们。有没有办法加载 xml 文件,因为它们是 globalresources ,并访问我的classes/cs/ashx 文件中的内容?
全局资源的问题是,如果将它们添加为嵌入的
资源,如果不重新编译它们,我就无法更改它们
这篇文章。如果我错了请纠正我。
谢谢。
Actually i'm using xml files for my web pages configuration , xml files contain everything and all the controls/content is loadded through theese XML files and it works , theese config files can change on the fly , and web pages just change their layout/content no need to recompile/redeploy , and i must keep this way of doing things.
The problem is that i'm loading these files like 20 times per page and when i want to access them from my classes/ashx files , i just keep opening them. Is there a way to load xml Files as they were globalresources , and access content from my classes/cs/ashx files?
the problem with global resources is that if add them as emmbded
resources , i can't change them without recompling them refering to
this post . Correct me if i'm wrong.
Thanks.
发布评论
评论(3)
您可以将文件存储在缓存、会话,应用程序 或 ViewState 对象。
我认为最适合的是
Cache
对象,因为您可以添加一些基于文件的依赖项,和您的对象将自动更新:You can store your files in Cache, Session, Application or ViewState objects.
I think most preferably for is
Cache
object, because you can add some dependencies based on files, and your objects will be automatically updated:在这种情况下,我使用一个助手:
我会使用这样的东西:
提供的委托每天只会被调用一次。如果该项目已在缓存中,则不会再次调用委托。
In situations like this, I use a helper:
which I would use something like this:
The supplied delegate will only be invoked once per day. If the item is already in cache, the delegate will not be invoked again.
您需要创建包装器来访问您的文件,该包装器将具有以下属性:
此外,还将创建它来缓存这些文件。了解如何使用缓存和文件 CacheDependency:使用 ASP.NET 缓存依赖项缓存文件
You need to create wrapper for accessing your files which will have properties like:
Also it would be create to cache these files. Take a look on using cache and file CacheDependency: Cache files using ASP.NET Cache Dependency