错误

iis部署asp .net core 3.1 web api接口上传文件,文件大于30MB就上传失败。c# - - - IIS服务器设置上传文件大小和上传时间_插入图片

解决

  1. 修改web.config文件 或者 配置 “配置编辑器”。
  2. 修改代码: 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>
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.

方式二:

双击打开 “配置编辑器”:c# - - - IIS服务器设置上传文件大小和上传时间_.net_02

设置参数:system.webServer/security/requestFiltering节点,更改为 2147483648

计算方式:
2GB = 2 * 1024 * 1024 * 1024 = 2,147,483,648
30MB ≈ 30 * 1024 *1024 = 31,457,280
默认上传文件大小最大为30MBc# - - - IIS服务器设置上传文件大小和上传时间_插入图片_03

设置上传时间

system.web/httpRuntime节点

delayNotificationTimeout: 获取或设置更改通知的延迟时间,单位为秒。
executionTimeout: 表示允许执行请求的最大时间限制,单位为秒
shutdownTimeout: 指定辅助进程关闭所允许的时间,单位为秒。

需要将 executionTimeout 设置为:01:00:00 (1小时),其他两个参数随意。

参数含义参考: processModel 元素(ASP.NET 设置架构)c# - - - IIS服务器设置上传文件大小和上传时间_插入图片_04

每次修改后点击应用:c# - - - IIS服务器设置上传文件大小和上传时间_上传_05

修改完成后,查看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-->
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.