ASP.NET uploads large files of unknown size

I want to use ASP.NET and IIS to load dynamically generated files into the browser for saving. I don't know the size of the file that will be generated.

In its current form, my code is generating data and using HttpResponse.Write () to send to the client. But the client sees no activity for about a minute before finally showing the save file dialog.

By default, IIS buffers the output to be sent to the client. It can be turned off, but it doesn't help in my case. The problem is how IIS chooses the package format.

If the size of the file is known in advance, I can set the length of the content in the header. If I turn off output buffering, then presumably IIS can start sending to the client right away.

But since I don't know the file size, IIS seems to buffer the output until a certain limit is reached (packet size or time, I don't know), and then sends the packet with the transfer-encoding set to fragmented.

I could try chunking the data myself, but is there a way to get IIS to chunking, but with a smaller batch size so that the dialog is shown earlier?

+1


a source to share


6 answers


There are currently no acceptable answers, but I can share what I've learned.

I am using IIS 6 and .NET framework 2.0.

It looks like IIS is buffering the output and not honoring my Flush () calls. In fact, Flush () actually slows down loading. It seems to just move output from one process to another in IIS, but less efficiently than if Flush () were not used.

Some interesting behavior showed up in testing. If the output was small enough, IIS added the length of the content to the response header and then sent it.



If the output was too big, after about 60 seconds IIS added the: chunked transfer encoding to the header, then added the appropriate hex number and sent what it had. From there, the output was streamed as my Flush () calls happened.

It didn't matter if I beat the data myself. IIS still buffers the output until its buffer is full.

Maybe there is a better way to set transfer encoding in a newer framework so that IIS 6 can handle it better.

Another possibility is to try different settings in Metabase.xml. I ran out of time before investigating further.

0


a source


Have you tried random calls to HttpResponse.Flush ()?



0


a source


Have you tried setting the BufferOutput property to false? Another thought (I don't know if that changes anything) is to write the file to the OutputStream instead of calling HttpResponse.Write()

.

0


a source


How do you not know the size of the file you are passing to the browser? And do you mean Response.BinaryWrite?

0


a source


Try something similar to:

byte[] response_bytes = ...
int offset = ...

using (Stream writeStream = HttpContext.Response.OutputStream)
{
    ...
    writeStream.Write(response_bytes, offset, response_bytes.Length);
}

      

0


a source


Response.BufferOutput = false;

      

return File(fileStream, contentType);

0


a source







All Articles