ASP.NET Overflow or underflow in the arithmetic operation when returning large file bigger 1 GB

后端 未结 3 854
攒了一身酷
攒了一身酷 2021-02-04 02:47

I went across some sort of limitation in ASP.NET. I reduced the problem into a sample project in ASP.NET MVC Project (created with Visual Studio 2010 and .NET 4) and the problem

3条回答
  •  挽巷
    挽巷 (楼主)
    2021-02-04 03:22

    Disable buffering in IIS will do the job:

    public ActionResult DownloadBigFile()
    {
        string file = @"C:\Temp\File.txt";
        var readStream = new FileStream(file, FileMode.Open, FileAccess.Read);
        Response.BufferOutput = false; //<-----
        return File(readStream, "text/plain", "FILE");
    }
    

    It really beats me why this is not the default ASP.Net MVC behavior when returning files. Especially when doing it with streams.

    • Related thread in forums.iis.net
    • MSDN: HttpResponseBase.BufferOutput

提交回复
热议问题