Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Response.Flush with MVC Result is not working

We are implementing long running process to download database content as xml with asp.net 3.

Total document generation time is about 3-5 minutes and we want to respond with first byte as soon as possible. We have overridden System.Web.Mvc.FileResult and are trying to do something like:

protected override void WriteFile(HttpResponseBase response)
{
   Stream outputStream = response.OutputStream;
   byte[] header = xmlExportService.XmlHeader();
   response.Flush();
   outputStream.Write(header, 0, header.Length);
   response.Flush();
   //// some long running generation here
}

On local iis under windows 7 I am gatting Save File dialog in browser. On production, windows server 2008 R2 there is no dialog until whole file is generated.

Any ideas?

like image 393
st78 Avatar asked Apr 25 '12 14:04

st78


2 Answers

Not sure if this helps anyone, but Response.Flush will not "work" if you have HTTP compression enabled. We enabled dynamic compression on our servers and the call to Response.Flush would just hang. After some research, it has to do with the fact that the server is waiting for all the output so it can "compress it and send it".

Since we are using MVC, I am considering using an attribute to dynamically control if compression is enabled for non-static pages. For now, we just got rid of the Response.Flush call in our Views.

like image 79
ProVega Avatar answered Oct 17 '22 02:10

ProVega


Have you seen this postings? Same questions, accepted answers, might be of help?

  • MVC 3 Response.Flush does not work
  • Response.Flush not working ASP.NET
like image 26
Display Name Avatar answered Oct 17 '22 02:10

Display Name