private static async Task SendFileToResponse(OwinResponse response, CrossAppDomainResponseFile file) { if(response.CanSendFile) { await response.SendFileAsync(file.Path, file.Length, file.Offset, CancellationToken.None); return; } var buffer = new byte[file.Length - file.Offset]; using (var stream = File.OpenRead(file.Path)) { stream.Seek(file.Offset, SeekOrigin.Begin); await stream.ReadAsync(buffer, 0, (int)file.Length); } await response.WriteAsync(buffer); }