Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the best practice for transferring huge binary files with ASP.NET?

Consider an ASP.NET page with this code:

while (read)
{
   Response.OutputStream.Write(buffer, 0, buffer.Length);
   Response.Flush();
}

The application should be highly performance-tuned and handle thousands on concurrent requests and the main purpose is transferring huge binary file to clients over high speed connections. I can do the job with an ASP.NET page, with HTTP Handler, IHttpAsyncHandler, ISAPI filter and ...

The question is what is the best choice for this purpose ?

like image 686
Xaqron Avatar asked Nov 05 '22 08:11

Xaqron


1 Answers

If the page is liable to be I/O bound then I'd go the Async road. But you should use the asynchronous read methods (if available) on your Stream object as well.

For more information see:

FileStream Constructor - with async example

To address your comment that you receive this data via a socket, you'll also find that most of the System.Net.Sockets namespace classes support asynchronous behaviour.

like image 163
Kev Avatar answered Nov 10 '22 18:11

Kev