我们的 ASP.NET C# web 应用程序在以下环境中使用 -.NET 框架 4 - IIS 7 - Windows 2008 - Visual Studio 2010.NET IDE - C# - HTTPS(SSL) 我们的 ASP.NET C# Web 应用程序将各种文件(如 jpgs、mp4、mp3、png、docx、txt 等)上传到名为 ClientBin 的文件夹中。 但是,如果我们将应用程序部署到 IIS7 服务器,我们必须授予我们应用程序的 Web 用户上传文件的权限。 我们授予\IIS_IUSRS 组在我们的 ClientBin 上传文件夹上执行、读取、写入和执行的权限。
网络用户可以上传大小小于大约 12MB 的文件。
但是,当网络用户上传超过大约 12MB 时,上传的文件在服务器的 ClientBin 上传文件夹中将为 0 字节。
在我们的 Web.config 中,我们对 httpRuntime 标记进行了以下配置:
<system.web>
...
.....
........
..............
<httpRuntime maxRequestLength="1048576" executionTimeout="50000"
useFullyQualifiedRedirectUrl="false" requestLengthDiskThreshold="15360"
minFreeThreads="8" minLocalRequestFreeThreads="4"
appRequestQueueLimit="100" />
</system.web>
在我们的 Web.config 中,我们对 requestLimits
标记进行了以下配置:
<system.webServer>
..............
.........................
<security>
<requestFiltering>
<requestLimits maxAllowedContentLength="2000000000" />
<fileExtensions>
<add fileExtension=".aspx" allowed="true" />
</fileExtensions>
</requestFiltering>
</security>
</system.webServer>
我还采用了不受欢迎的方法,通过创建以下设置来修改 machine.config 文件:
<system.web>
<processModel responseDeadlockInterval="0:09:00"
responseRestartDeadlockInterval="0:09:00" />
.....................
..........................................
.............................................................
</system.web>
我还采取了以下步骤: 我检查了事件查看器和 IIS 日志,但没有显示奇怪。
大小小于大约 12 MB 的文件可以正确上传。
重要的是要注意文件确实上传了,但最终都是 0Kb。上传的文件名和类型与我桌面上的相同,但大小为 0Kb。我桌面上的那个大约有 75MB。
ASP.NET 和 IIS 不会抛出任何错误页面。
为什么上传到 ASP.NET Web 应用程序的大于 12MB 的文件显示为 0MB?
最佳答案
尝试增加 requestLengthDiskThreshold
以匹配 maxRequestLength
<configuration>
<system.web>
<!-- maxRequestLength and requestLengthDiskThreshold is in Kilobytes-->
<httpRuntime maxRequestLength="204800" requestLengthDiskThreshold="204800" />
</system.web>
<system.webServer>
<security>
<requestFiltering>
<!-- maxAllowedContentLength is in Bytes not Kilobytes -->
<requestLimits maxAllowedContentLength="204800000" />
</requestFiltering>
</security>
</system.webServer>
</configuration>
此外,您是否尝试过使用更全面的 ASP.NET 上传控件,例如 Telerik RadUpload模块?它可以免费试用,看看它是否能解决您的问题。
关于c# - 为什么上传到 ASP.NET Web 应用程序的大于 12MB 的文件显示为 0MB?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13647508/