c# - - - IIS服务器设置上传文件大小和上传时间

错误

iis部署asp .net core 3.1 web api接口上传文件,文件大于30MB就上传失败。
在这里插入图片描述

解决

  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>

方式二:

双击打开 “配置编辑器”:
在这里插入图片描述

设置参数:
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-->
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值