我有一个 ASP.NET Core 2.2 MVC 应用程序,文件上传正常,直到文件大小约为 55MB,但当我想上传更大的文件时,它返回 HTTP 错误代码 502.3,例如 80MB 文件。这是它的代码: public string PutSessions(SESSIONViewModel model) { var remoteFolderPath = _config.Value.FileDestinationAddress; var baseUrl = _config.Value.BaseUrl;
var file = Path.Combine(remoteFolderPath, model.File.FileName);
using (var stream = new FileStream(file, FileMode.Create))
{
model.File.CopyToAsync(stream);
}
...
return ...;
}
我添加了一个 web.config 到它:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<location path="." inheritInChildApplications="false">
<system.webServer>
<handlers>
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified" />
</handlers>
<aspNetCore processPath=".\MyApp.Web.exe" stdoutLogEnabled="false" requestTimeout="01:30:00" stdoutLogFile=".\logs\stdout" hostingModel="InProcess" />
<httpCompression>
<dynamicCompression>
<add mimeType="text/event-stream" enabled="false" />
</dynamicCompression>
</httpCompression>
<security>
<requestFiltering>
<!-- This will handle requests up to 500MB -->
<requestLimits maxAllowedContentLength="524288000" />
</requestFiltering>
</security>
</system.webServer>
<system.web>
<httpRuntime maxRequestLength="524288000" />
</system.web>
</location>
</configuration>
我认为 80 MB 的文件大小不会太大而不能返回错误。