Asp.net MVC 上传大文件(超过50M)的设置

在上传文件时,比较小的文件会直接上传成功,大的文件页面报错:“文件超过了最大请求长度”。

经过查明:

需要在配置文件里面设置文件上传限定的两个属性值:maxAllowedContentLength,maxRequestLength 允许上传文件的长度,和请求的长度,两个大小需要设置一致,如果不一致,则以请求长度为准。

The maximum request size in kilobytes. The default size is 4096 KB (4 MB). 默认请求长度只有4M.   设置的单位都为byte

<system.web>
  <httpRuntime maxRequestLength="2147483647" executionTimeout="36000" delayNotificationTimeout="36000"/>
</system.web>

<system.webServer>
  <security>
    <requestFiltering>
      <!--<requestLimits maxAllowedContentLength="1073741824"/>-->
      <requestLimits maxAllowedContentLength="2147483648"/>
    </requestFiltering>
  </security>
</system.webServer>

以上是对某个站点或者某个应用上限制大小,配置的web.config

注意:最好同步地对IIS上面的配置文件进行修改设置。

要以上配置有效的前提是,要确保applicationhost.config中对该项修改的权限已经放开。

applicationhost.config文件路径在 C:\Windows\System32\inetsrv\config 下

可通过如下设置进行更改:

modify the overrideModeDefault from "Deny" to "Allow" like so: 

<sectionGroup name="system.webServer">

  <sectionGroup name="security">
       <section name="requestFiltering" overrideModeDefault="Allow" />

  </sectionGroup>
</sectionGroup>

确认修改过applicationhost.config中上述设置以后,再进行web.config中的设置。

 

二: 也可以直接设置服务器级别的文件上传大小,在applicationhost.config文件中加上以下字段

<system.webServer>
   <security>
       <requestFiltering>
              <requestLimits maxAllowedContentLength="2147483647" />
       </requestFiltering>
   <security>
<system.webServer>

也可以使用命令模式修改:

也可以使用命令行模式修改applicationhost.config:

%windir%\system32\inetsrv\appcmd set config -section:requestFiltering -requestLimits.maxAllowedContentLength:2147483647

前端:

服务端上传目录:

已无限制,可以上传超50M大小的文件。

DEMO下载地址:https://dwz.cn/fgXtRtnu


 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值