Response.Flush()仅适用于Firefox [英] Response.Flush() only works with Firefox

查看:132
本文介绍了Response.Flush()仅适用于Firefox的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  Response.Write(Processing。 ..); 
Response.Flush();
System.Threading.Thread.Sleep(5000);
Response.Write(Finish);
Response.End();

在Firefox中,它可以按预期工作,但在IE8中,Safari和Chrome会等待所有代码处理完毕然后显示整个文本。



我尝试发送一个更好的HTML格式,如下面的例子,但是我得到了相同的结果:

  Response.Write(< html>< head>< title>测试< / title>< / head>< body>正在处理... < /体>< / HTML>中); 
Response.Flush();
System.Threading.Thread.Sleep(5000);
Response.Write(Finish);
Response.End();

谢谢!

解决方案

您面临的问题是您发送的回复仍然不完整。即使你将缓冲区中的任何东西都刷新到浏览器,仍然等待浏览器等待响应结束或处理它到目前为止的状态 - 这是浏览器之间的区别。

更糟的是,你可以期望来自位于你的服务器和浏览器之间的互联网上的一些中间节点集中器,防火墙等的相同行为。



底线是,如果你想确保浏览器对你的数据流做些什么,你必须用Response.End来完成。换句话说,如果你想先发送你的一些响应数据并延迟发送其余的数据,那么最好的选择是将响应分成两部分,完成第一个响应数据,然后完成第一个响应数据,分别下载第二部分


I am trying to send some content to the client before doing some lengthy work:

Response.Write("Processing...");
Response.Flush();
System.Threading.Thread.Sleep(5000);
Response.Write("Finish");
Response.End();

In Firefox it works as expected but in IE8, Safari and Chrome it waits until all the code is processed and then shows the whole text.

I have tried sending a better formed HTML like the below sample but I get the same results:

Response.Write("<html><head><title>test</title></head><body>Processing...</body></html>");
Response.Flush();
System.Threading.Thread.Sleep(5000);
Response.Write("Finish");
Response.End();

Thank you!

解决方案

The problem you are facing is that the response you are sending is still incomplete. Even though you flush whatever is in the buffers to the browser, it is still up to the browser to wait for the response end or process what it's got so far - hence the difference between browsers.

What's even worse is that you can expect the same behavior from some intermediate nodes concentrators, firewalls, etc. located on the internet between your server and the browser.

The bottom line is that if you want to ensure that browser does something with your data stream you have to complete it with Response.End.

In other words if you want to send some of your response data first and delay sending the rest your better option is to break the response in two, complete the first one and download the second part separately

这篇关于Response.Flush()仅适用于Firefox的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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