简体   繁体   中英

embed html files in an asp.net page

I have webpages that most of their content are created via plugins by accessing database many many times. But I have considered that as the created result will always be the same (till user make changes to plugins), to make the html result each time the user makes changes and load the constant html each time page loads.

This is What I have done:

<%= System.IO.File.ReadAllText(Filename); %>

and in some pages I might have to read several files. Would this be better than creating pages each time or reading from files are slower?

what would you suggest?

What you need is caching and that can be implemented in many ways. Writing to temp files and updating those when the content changes is one way. Using an in-memory cache is another and ASP.NET has that provided, also with expiration times, if required. Also you can always use a combination of these techniques, for example, if you have lots of data that changes once a month but it's accessed very often. Then you could save the HTML into a file and on first request save it in memory cache also (with expiration).

I'd say that usually loading a file is faster than doing database queries, but if you need to load a lot of files, then it might get slower. Depends on the server system. Memory cache will help in this case naturally and the server might also cache the file contents.

So it's not a simple yes/no or 'do this' answer for caching. I'd suggest doing a search on the web for asp.net and caching, there probably is at least a similar case to yours somewhere.

More information from MSDN: ASP.NET Caching: Techniques and Best Practises

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM