Progressively stream the output of an ASP.NET page - or render a page outside of an HTTP request
Posted
by Evgeny
on Stack Overflow
See other posts from Stack Overflow
or by Evgeny
Published on 2010-05-13T01:33:12Z
Indexed on
2010/05/13
1:44 UTC
Read the original article
Hit count: 255
I have an ASP.NET 2.0 page with many repeating blocks, including a third-party server-side control (so it's not just plain HTML). Each is quite expensive to generate, in terms of both CPU and RAM. I'm currently using a standard Repeater control for this.
There are two problems with this simple approach:
- The entire page must be rendered before any of it is returned to the client, so the user must wait a long time before they see any data. (I write progress messages using
Response.Write
, so there is feedback, but no actual results.) - The ASP.NET worker process must hold everything in memory at the same time. There is no inherent needs for this: once one block is processed it won't be changed, so it could be returned to the client and the memory could be freed.
I would like to somehow return these blocks to the client one at a time, as each is generated. I'm thinking of extracting the stuff inside the Repeater into a separate page and getting it repeatedly using AJAX, but there are some complications involved in that and I wonder if there is some simper approach. Ideally I'd like to keep it as one page (from the client's point of view), but return it incrementally.
Another way would be to do something similar, but on the server: still create a separate page, but have the server access it and then Response.Write()
the HTML it gets to the response stream for the real client request. Is there a way to avoid an HTTP request here, though? Is there some ASP.NET method that would render a UserControl or a Page outside of an HTTP request and simply return the HTML to me as a string?
I'm open to other ideas on how to do this as well.
© Stack Overflow or respective owner