逐步流ASP.NET页面的输出 - 或渲染页面的HTTP请求外 [英] Progressively stream the output of an ASP.NET page - or render a page outside of an HTTP request

查看:471
本文介绍了逐步流ASP.NET页面的输出 - 或渲染页面的HTTP请求外的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个ASP.NET 2.0页有许多重复的块,其中包括第三方服务器端控件(所以它不只是普通的HTML)。每个是相当昂贵的产生,在这两个CPU和RAM的条款。我目前使用的是标准的Repeater控件这一点。

有两个问题简单的方法:

  1. 整个页必须被呈现前任何它被返回给客户端,因此,用户必须等待很长的时间,才看到的任何数据。 (我写的使用进度信息的Response.Write ,所以反馈的,但没有实际的效果。)
  2. 在ASP.NET工作进程必须保持在同一时间都在内存中。没有此没有内在需求:一旦一个块被处理就不会改变,因此它可以被返回到客户端和所述存储器可以被释放

,我想在一个时间不知何故返回这些块到客户端之一,因为每个被产生。我想提取的转发器内的东西到一个单独的页面,并使用AJAX得到它反复的,但也有一些并发症涉及这一点,我不知道是否有一些假笑的做法。理想情况下,我想保持它作为一个页面(但从客户的角度),但逐步归还。

另一种方法是做同样的事情,但在服务器上:还是创建一个单独的页面,但有服务器的访问,然后的Response.Write()它得到了的真正的客户端请求的响应流的HTML。有没有一种方法,以避免一个HTTP请求在这里,虽然?有一些会呈现一个用户控件或页面的HTTP请求外,并简单地返回HTML我作为一个字符串?ASP.NET方法

我愿意就如何做到这一点以及其他的想法。

解决方案
  

另一种方法是做同样的事情,但在服务器上:还是创建一个单独的页面,但服务器访问它,然后回复于(),它得到了真正的客户端请求的响应流的HTML。

如果您提取每个中继行的内容到用户控件你可以做到这一点。然后,您可以动态地加载控件(如果需要的话)使用 LoadControl 方法,给它适当的数据应该呈现(调用DataBind如果需要的话),那么使用的渲染方法。这基本上是你脑子里想什么,而无需创建一个全新的请求的一塌糊涂。

免责声明:的,我不知道这是否会在总执行时间的性能比当前解决方案更好或更坏

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:

  1. 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.)
  2. 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.

解决方案

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.

You could do this if you extract the contents of each repeater row into a UserControl. You could then load the control dynamically (if need be) using LoadControl method, give it the proper data it should render (call DataBind if necessary) then render it to the response stream using the Render method. This is basically what you had in mind without the mess of creating a whole new request.

Disclaimer: I don't know if this will perform better or worse than your current solution in terms of total execution time.

这篇关于逐步流ASP.NET页面的输出 - 或渲染页面的HTTP请求外的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆