使用Response.close / .end将流下载到浏览器,如何避免中止其余响应? [英] Download stream to browser using Response.close / .end, how to avoid to abort the rest of response?

查看:168
本文介绍了使用Response.close / .end将流下载到浏览器,如何避免中止其余响应?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在服务器上生成了5MB的MemoryStream,它需要作为excel文件提供给用户。

I have a 5MB MemoryStream generated on server and it needed serving to users as an excel File.

我使用Response.close使其可下载。但是可以肯定的是,它将中止页面上的所有请求/响应。

I used Response.close to make it downloadable. But for sure, it will abort all requests / response on the page.

我知道使用下载页面可能会对线程有所帮助,但是如何将MemoryStream传递给下载页面?通常,它应该将文件URL传递到该页面。

I known using a download page may help the thread, but how do I pass the MemoryStream to the download page? Normally it should pass a file URL to that page.

更多评论:
1.首先,我想将文件流式传输到客户。要使其具有下载属性,可以使用它代替Response.close()。
2.第二,在客户端下载期间,我想显示一个处理栏(JUST AN IMAGE)。 Response.close将停止JavaScript函数隐藏该栏。

More comments: 1. First, I want stream the file to client. To make it download property, which can be used instead of Response.close(). 2. Second, during the client download, I want to show an processing bar(JUST AN IMAGE). The Response.close will stop the JavaScript function to hidden the bar.

仍然感谢。困难在于,在 Response.End CompleteRequest 之后,已发送Http标头。我无法访问任何前端的内容。我应该真正使用一个处理过程逻辑以及用于下载文件的单独页面。

Thanks anyway. The difficulty is that after Response.End or CompleteRequest the Http header has been sent. I'll not be able to access anything in the frond end. I should really use a separate page that handles process logic as well as is used to download file.

推荐答案

您的问题有点不清楚。您询问如何结束响应而不结束响应。您是说要在响应刷新到客户端后其余代码继续运行吗?还是您对实际响应不正确有疑问?

Your question is a little unclear. You ask how to end the response without ending the response. Do you mean you want to rest of the code to run after the response is flushed to the client? Or are you having a problem with the actual response not being right?

使用Response.Close()可能会出现问题,因为它基本上会重置与客户端的HTTP连接。请参阅此MSDN博客帖子 MSDN Response.Close()参考

Using Response.Close() could be problematic as it basically resets the HTTP connection to the client. See This MSDN Blog Post and MSDN Response.Close() Reference.

如果您可以更详细地描述问题,我可以更新我的答案。

If you can describe the problem you are having with more detail I can update my answer.

这篇关于使用Response.close / .end将流下载到浏览器,如何避免中止其余响应?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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