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.


  1. Yes, it is buffering.
  2. Flush pushes the cached content to the browser. If it is never pushed, you won't get a save dialog box.
  3. Hard to tell without seeing the exact files/URLs/Streams you are using.
  4. 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.
  5. See #1 & 2.

  1. Yes; this is normal.
  2. 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.
  3. 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; write

    response.AppendHeader("Content-Length", new FileInfo(path).Length.ToString());
    
  4. I recommend 4K; I don't have any hard basis for the recommendation.
  5. 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.