如何允许使用带有C#的.NET Core MVC上传大文件大小



我正在使用带有C#的.NET Core 3.1 MVC来制作web应用程序。我想允许用户上传文件大小不受限制的文件到我的服务器。

我尝试了以下方法:

https://github.com/dotnet/aspnetcore/issues/15431

增加Asp.Net核心中的上传文件大小

请记住,我的主要目标是允许上传任何大小的文件。

我也试过

[HttpPost]
[ValidateAntiForgeryToken]
//[RequestFormLimits(MultipartBodyLengthLimit = 107374182400)] //100 GB
//[RequestSizeLimit(107374182400)]
//[DisableRequestSizeLimit, RequestSizeLimit(107374182400)]
public async Task<IActionResult> ImportDB(int t = 0)
{}

它适用于基于Linux的服务器,但不适用于IIS服务器

我的web.config文件为4 GB我想要不受限制的文件大小

<?xml version="1.0" encoding="utf-8"?>
<configuration>
<!-- To customize the asp.net core module uncomment and edit the following section. 
For more info see https://go.microsoft.com/fwlink/?linkid=838655 -->
<system.webServer>
<handlers>
<remove name="aspNetCore" />
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModuleV2" resourceType="Unspecified" />
</handlers>
<aspNetCore processPath="%LAUNCHER_PATH%" arguments="%LAUNCHER_ARGS%" stdoutLogEnabled="false" stdoutLogFile=".logsstdout" hostingModel="InProcess" />   
<!-- Add this section for file size... -->
<security>
<requestFiltering>
<!--Measured in Bytes--> 
<requestLimits maxAllowedContentLength="4294967295" />
<!--4 GB-->
</requestFiltering>
</security>
</system.webServer>
</configuration>

上传文件的大小是考虑存储容量的一个重要因素。不允许最终用户上传大小不受限制的文件,因为在最坏的情况下,这只会导致一个用户填满服务器的存储容量。

如果你想上传一个很大的文件,也许你可以试着把文件分成更小的部分来上传。这里是参考:上传和下载大文件

最新更新