C# ASP.NET 文件上传控件允许的最大文件大小
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15248934/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Maximum file size allowed by ASP.NET file upload Control
提问by Pratik
I am using File upload control in ASP.Net, followed the below blogs approach.
我在 ASP.Net 中使用文件上传控件,遵循以下博客方法。
http://weblogs.asp.net/jgalloway/archive/2008/01/08/large-file-uploads-in-asp-net.aspx
http://weblogs.asp.net/jgalloway/archive/2008/01/08/large-file-uploads-in-asp-net.aspx
The 4MB default is set in machine.config, but you can override it in you web.config. For instance, to expand the upload limit to 20MB, you'd do this:
4MB 默认值在 machine.config 中设置,但您可以在 web.config 中覆盖它。例如,要将上传限制扩展到 20MB,您可以这样做:
<system.web>
<httpRuntime executionTimeout="240" maxRequestLength="20480" />
</system.web>
Question:Till what level(MAX size) i can increase the requested length and what will be performance impact on site if we allowed user to upload 50-60 MB files also.
问题:如果我们允许用户同时上传 50-60 MB 的文件,我可以将请求的长度增加到什么级别(最大大小),以及会对网站性能产生什么影响。
采纳答案by Davin Tryon
The 'theoretical' max level for the maxRequestLength
field is the max value for signed 32-bit integer data type (Int32.MaxValue
).
该maxRequestLength
字段的“理论”最大级别是有符号 32 位整数数据类型 ( Int32.MaxValue
)的最大值。
However, you are going to have to test the upload in order to understand your performance.
但是,您将不得不测试上传以了解您的性能。
EDIT:
编辑:
From a Microsoft support ticket:
Theoretically, the maximum file upload size is fairly large. However, because of ASP.NET health monitoring, you cannot upload very large files in ASP.NET. The ASP.NET worker process has a virtual address space of 2 gigabytes (GB). However, the ASP.NET worker process only uses a little more than 1 GB because of health monitoring and memory fragmentation.
During the upload process, ASP.NET loads the whole file in memory before the user can save the file to the disk. Therefore, the process may recycle because of the memoryLimit attribute of the processModel tag in the Machine.config file. The memoryLimit attribute specifies the percentage of physical memory that the ASP.NET worker process can exhaust before the process is automatically recycled. Recycling prevents memory leaks from causing ASP.NET to crash or to stop responding.
Additionally, other factors play a role in the maximum file size that can be uploaded. These factors include available memory, available hard disk space, processor speed, and current network traffic. With regular traffic of files being uploaded, Microsoft recommends that you use a maximum file size in the range of 10 to 20 megabytes (MB). If you rarely upload files, the maximum file size may be 100 MB.
Note You can upload files that are larger than 100 MB in ASP.NET. However, Microsoft recommends that you follow the maximum file upload sizes that are mentioned in this article. To determine more precise file sizes, perform stress testing on computers that are similar to the ones that will be used in production.
理论上,最大文件上传大小是相当大的。但是,由于 ASP.NET 运行状况监视,您无法在 ASP.NET 中上传非常大的文件。ASP.NET 辅助进程具有 2 GB 的虚拟地址空间。但是,由于运行状况监视和内存碎片,ASP.NET 工作进程仅使用略多于 1 GB。
在上传过程中,ASP.NET 在用户可以将文件保存到磁盘之前将整个文件加载到内存中。因此,由于 Machine.config 文件中 processModel 标记的 memoryLimit 属性,进程可能会回收。memoryLimit 属性指定 ASP.NET 辅助进程在进程自动回收之前可以耗尽的物理内存百分比。回收可防止内存泄漏导致 ASP.NET 崩溃或停止响应。
此外,其他因素也会影响可上传的最大文件大小。这些因素包括可用内存、可用硬盘空间、处理器速度和当前网络流量。对于上载文件的常规流量,Microsoft 建议您使用 10 到 20 兆字节 (MB) 范围内的最大文件大小。如果您很少上传文件,则最大文件大小可能为 100 MB。
注意您可以在 ASP.NET 中上传大于 100 MB 的文件。但是,Microsoft 建议您遵循本文中提到的最大文件上传大小。要确定更精确的文件大小,请在与生产中使用的计算机类似的计算机上执行压力测试。