I have a file that I am attempting to return to a web client using HttpResponseMessage. The code works, but the transfer speed is five to ten times slower than simply fetching the same file from an IIS virtual directory. I have verified that it's not an encoding issue by monitoring my download bandwidth consumption, which never breaks 250 kilobytes per second, where the direct download from IIS is typically five times that.
Here's the code, stripped to its essentials and with error trapping 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;
Am I missing something?