ASP.NET溢出或算术运算返回溢大文件的时候更大的1 GB [英] ASP.NET Overflow or underflow in the arithmetic operation when returning large file bigger 1 GB

查看:2546
本文介绍了ASP.NET溢出或算术运算返回溢大文件的时候更大的1 GB的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我碰到一些在ASP.NET限制了。
我减少了问题到ASP.NET MVC项目的示例项目(使用Visual Studio 2010和.NET 4中创建)和问题仍然存在:

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 still occurs:

在一个MVC控制器我有一个提供文件下载的方法:

In a MVC Controller I have a method which provides a file download:

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

当文件小于1 GB的下载工作正常,
上述1 GB抛出一个异常:溢出或下溢的算术运算与以下细节:

When the file is below 1 GB the download works fine, above 1 GB an exception is thrown: "Overflow or underflow in the arithmetic operation" with the following details:

 Overflow or underflow in the arithmetic operation.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.ArithmeticException: Overflow or underflow in the arithmetic operation.

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:


[ArithmeticException: Overflow or underflow in the arithmetic operation.]

[HttpException (0x80004005): An error occurred while communicating with the remote host. The error code is 0x80070216.]
   System.Web.Hosting.IIS7WorkerRequest.RaiseCommunicationError(Int32 result, Boolean throwOnDisconnect) +4081269
   System.Web.Hosting.IIS7WorkerRequest.FlushCore(Boolean keepConnected, Int32 numBodyFragments, IntPtr[] bodyFragments, Int32[] bodyFragmentLengths, Int32[] bodyFragmentTypes) +12233777
   System.Web.Hosting.IIS7WorkerRequest.FlushCachedResponse(Boolean isFinal) +847
   System.Web.HttpResponse.UpdateNativeResponse(Boolean sendHeaders) +1110
   System.Web.HttpRuntime.FinishRequestNotification(IIS7WorkerRequest wr, HttpContext context, RequestNotificationStatus& status) +336


Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET  Version:4.0.30319.34009 

问题是可重复的,但我没有找到有关此问题的任何信息。我怎样才能prevent这种问题还是如何管理大下载(> 1GB)?

The problem is reproducible but I did not find any information about this behavior. How can I prevent this kind of problem or how can I manage big downloads (> 1GB)?

先谢谢了。

推荐答案

在IIS禁用缓存将做的工作:

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");
}

这真的打败我,为什么返回文件时,这是不是默认的ASP.Net MVC行为。特别是随着流这样做的时候。

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

这篇关于ASP.NET溢出或算术运算返回溢大文件的时候更大的1 GB的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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