ASP.NET 页面渲染
ASP.NET 页面如何从服务器渲染到客户端浏览器?问题是,考虑页面有一个页眉和页脚,它们是用户控件并包含许多服务器控件。
一旦 ASP.NET 获得一些正在以各自的 HTML 形式呈现和转换的控件,它是否会开始将 HTML 发送到客户端浏览器?或者它是否等待整个页面在服务器上呈现并转换为 HTML,然后将页面 HTML 发送回浏览器。
我发现我们网站的“页面标题”很早就显示了,然后页面完全加载需要太多时间。我想清楚这个概念,无论是服务器花费时间还是客户端脚本、图像等都是罪魁祸首。据此我们将开始优化。
具体来说,我有兴趣了解输出流(在响应对象中)如何发送到客户端浏览器?一旦整个页面在输出流中渲染或批量发送到客户端(即渲染很少的控件并通过输出流发送到浏览器 - >然后渲染更多控件等等......),输出流是否会刷新?
抱歉,如果我对问题还不够清楚。
How does the ASP.NET page rendering happens from Server to Client Browser? The question is, consider the Page has a Header and Footer which are User controls and contain many server controls.
Does ASP.NET start sending the HTML to client browser, once it gets some of the controls being rendered and converted in their respective HTML? Or does it wait for the whole page to be rendered and converted in HTML on Server, and then it sends back the Page HTML to the browser.
I am seeing that the "Page Title" of our website is shown much before and then the page takes too much time in loading completely. I want to be clear on this concept whether its server that is taking time or the client side scripts, images etc.. are the culprit. Accordingly we will start the optimizations.
Specifically I am interested in knowing how the outputstream (in response object) is sent to the Client Browser? Is the outputstream flushed once whole page is rendered in outputstream or it is sent to client in batches (i.e. few controls rendered and sent to browser via outputstream --> then some more controls are rendered and so on...)?
Sorry if am not clear enough on the problem.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
在调试方面,您可以打开 .NET 跟踪 查看服务器端花费时间的情况,
并使用 google chrome 或 firefox 的 firebug 查看客户端花费时间的情况。
in terms of debugging you can turn .NET tracing on to see whats taking the time on the server side,
and use google chrome or firebug for firefox to see whats taking the time on the client side.
我相信这是由 Response.BufferOutput 或类似的东西(手头没有参考)控制的,以确定它是否应该在准备好后立即开始发送 HTML,或者是否应该将其存储在缓冲区中并等待直到一切都完成然后发送。
I believe this is controlled by
Response.BufferOutput
or something similar(no reference at hand) to determine if it should start sending out HTML as soon as it's ready or if it should store it in a buffer and wait until everything is done and then send it.我正在寻找的答案是关于渲染方式,流如何发送到客户端,可能有两种方式,要么在生成后立即以多个块的形式发送,要么缓存并存储直到整个页面渲染完毕然后发送给客户。
我得到了答案: http://www .asp.net/aspnet/overview/aspnet-and-visual-studio-2012/whats-new
“通常 ASP.NET 在应用程序创建响应字节时缓冲它们。然后 ASP.NET 执行单个在请求处理结束时对累积缓冲区进行发送操作
如果缓冲的响应很大(例如,将大文件流式传输到客户端),则必须定期调用 HttpResponse.Flush 将缓冲的输出发送到客户端并保留内存。但是,由于 Flush 是同步调用,因此在可能长时间运行的请求期间,迭代调用 Flush 仍然会消耗一个线程。”
谢谢大家的帮助!!!
The answer I was looking for was regarding the rendering way, how is stream sent to client, there could be two ways, Either directly sending it as soon as it is generated, in multiple chunks, Or cache and store until whole page is rendered and then send it to client.
I got the answer at: http://www.asp.net/aspnet/overview/aspnet-and-visual-studio-2012/whats-new
"Normally ASP.NET buffers the response bytes as they are created by an application. ASP.NET then performs a single send operation of the accrued buffers at the very end of request processing.
If the buffered response is large (for example, streaming a large file to a client), you must periodically call HttpResponse.Flush to send buffered output to the client and keep memory usage under control. However, because Flush is a synchronous call, iteratively calling Flush still consumes a thread for the duration of potentially long-running requests."
Thank you all for your help!!!
用户控件先于 .aspx 页面本身的控件呈现。
查看页面生命周期
User controls are rendered before controls on the .aspx page itself.
Take a look at the Page Life Cycle
如果您看到页面标题显示但在我怀疑有其他文件(图像、javascript、css 等)阻止页面在浏览器中呈现(而不是页面中的 html)后,页面不会呈现一段时间
Fiddler should help determine where the bottleneck is, if you're seeing the page title show up but the page doesn't render for a bit after I'd suspect there are other files (images, javascript, css, etc) that are holding up the page from rending in the browser and not the html in the page
页面渲染。在此阶段,将保存页面的视图状态和所有控件。页面为每个控件调用 Render 方法,并将呈现的输出写入页面的 Response 属性的 OutputStream 类。
Page rendering . at this stage, view state for the page and all controls are saved. The page calls the Render method for each control and the output of rendering is written to the OutputStream class of the Page's Response property.