Downloading binary files is slow

I have a file that I am trying to return to the web client using HttpResponseMessage. The code works, but the transfer speed is five to ten times slower than just getting the same file from the IIS virtual directory. I have verified that this is not a coding problem by monitoring the download bandwidth consumption, which never interrupts 250 kilobytes per second, where direct download from IIS is usually five times as large.

Here, the code is divided into its main points and with the removal of errors removed for clarity:

// Succeeded in getting the stream opened, so return with HTTP 200 status to the client.
var stream = new FileStream(uncPath, FileMode.Open,FileAccess.Read, FileShare.Read);
HttpResponseMessage result = new HttpResponseMessage(HttpStatusCode.OK);
result.Content = new StreamContent(stream);
result.Content.Headers.ContentType = new MediaTypeHeaderValue(MimeExtensionHelper.GetMimeType(uncPath)); 
return result;

Did I miss something?

+4
source share

All Articles