asp.netbrowserdownloadstreamresponse

Download stream to browser using Response.close / .end, how to avoid to abort the rest of response?


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

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

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.

Any ideas?

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.

So how to achieve the both requires? Thanks

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.


Solution

  • 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?

    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.