Some questions about writing on ASP.NET response stream
For #3 you need to set the content-length header in your http-response. Many of those values come from http headers.
I believe you can change the bufferring by changing a buffering property on the response object to false. Haven't done it in a while so I don't remember what it might be.
- Yes, it is buffering.
- Flush pushes the cached content to the browser. If it is never pushed, you won't get a save dialog box.
- Hard to tell without seeing the exact files/URLs/Streams you are using.
- I think the factors depends on how sluggish your page is, really. You will have better performance toward 4k. And perhaps, the lower value will be better to accommodate slower connections.
- See #1 & 2.
- Yes; this is normal.
- If you never flush, the browser doesn't get any response until the server finishes (Not even the
Content-Disposition
header). Therefore, it doesn't know to show a file dialog. The
Content-Length
header only gets set if the entire response is buffered (If you never flush) or if you set it yourself. In this case, you can and should set it yourself; writeresponse.AppendHeader("Content-Length", new FileInfo(path).Length.ToString());
- I recommend 4K; I don't have any hard basis for the recommendation.
- This method is the best way to do it. By calling
Flush
inside the loop, you are sending the response down the wire immediately, without any buffering. However, for added performance, you can use GZIP compression.