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

查看:28
本文介绍了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 返回文件的 Stream 以及其他响应标头.虽然这适用于较小的文件,但较大的文件会生成 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天全站免登陆