错误
iis部署asp .net core 3.1 web api接口上传文件,文件大于30MB就上传失败。
解决
- 修改web.config文件 或者 配置 “配置编辑器”。
- 修改代码:https://blog.csdn.net/weixin_48430685/article/details/126399577
设置上传文件大小
方式一:
修改 web.config 文件,在 <configuration>
节点下最后面添加如下内容:
<system.webServer>
<security>
<requestFiltering>
<requestLimits maxAllowedContentLength="2147483648" />
</requestFiltering>
</security>
</system.webServer>
<system.web>
<httpRuntime delayNotificationTimeout="3600" executionTimeout="3600" shutdownTimeout="3600" />
</system.web>
方式二:
双击打开 “配置编辑器”:
设置参数:
system.webServer/security/requestFiltering
节点,更改为 2147483648
计算方式:
2GB = 2 * 1024 * 1024 * 1024 = 2,147,483,648
30MB ≈ 30 * 1024 *1024 = 31,457,280
默认上传文件大小最大为30MB
设置上传时间
system.web/httpRuntime
节点
delayNotificationTimeout: 获取或设置更改通知的延迟时间,单位为秒。
executionTimeout: 表示允许执行请求的最大时间限制,单位为秒
shutdownTimeout: 指定辅助进程关闭所允许的时间,单位为秒。
需要将 executionTimeout 设置为:01:00:00 (1小时),其他两个参数随意。
参数含义参考:processModel 元素(ASP.NET 设置架构)
每次修改后点击应用:
修改完成后,查看web.config
文件内容,修改的配置已保存在 web.config
文件中:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<location path="." inheritInChildApplications="false">
<system.webServer>
<handlers>
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModuleV2" resourceType="Unspecified" />
</handlers>
<aspNetCore processPath=".\Test.exe" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" hostingModel="inprocess" />
</system.webServer>
</location>
<system.webServer>
<security>
<requestFiltering>
<requestLimits maxAllowedContentLength="2147483648" />
</requestFiltering>
</security>
</system.webServer>
<system.web>
<httpRuntime delayNotificationTimeout="3600" executionTimeout="3600" shutdownTimeout="3600" />
</system.web>
</configuration>
<!--ProjectGuid: 4e170462-d0bf-4a5e-91ea-38c1ab7cf462-->