ASP.NET MVC:从FileResult返回大量数据 [英] ASP.NET MVC: Returning large amounts of data from FileResult

查看:388
本文介绍了ASP.NET MVC:从FileResult返回大量数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在MVC4中有一个文件浏览器应用程序,可让您从控制器下载选定的文件.

I have a file browser application in MVC4 that allows you to download a selected file from a controller.

当前,FileResult返回文件的流以及其他响应头.尽管这对于较小的文件来说效果很好,但是较大的文件会生成OutOfMemoryException.

Currently, the FileResult returns the Stream of the file, along with the other response headers. While this works fine for smaller files, files that are larger generate an OutOfMemoryException.

我想做的是从控制器传输文件,而不是以类似于WebForms中HttpReponse.TransmitFile的方式在内存中进行缓冲.

What I'd like to do is transmit the file from the controller, without buffering in memory in a fashion similiar to HttpReponse.TransmitFile in WebForms.

这怎么完成?

推荐答案

您可以在返回文件结果之前禁用响应缓冲区.

You can disable the response buffer before you return the file result.

Response.BufferOutput = false;
return File(fileStream, contentType);

这篇关于ASP.NET MVC:从FileResult返回大量数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆