MVC中上传文件大小限制的解决办法

在Web.Config文件中配置限制上传文件大小与时间。 

需要在配置文件里面设置文件上传限定的两个属性值:maxAllowedContentLength,maxRequestLength 允许上传文件的长度,和请求的长度,两个大小需要设置一致,如果不一致,则以请求长度为准。
maxRequestLength属性:用于防止服务器攻击,例如因用户向服务器发送大型文件而导致的拒绝访问。默认值为4096(4MB)
ExecutionTimeout属性:指定在ASP.NET应用程序自动关闭前,允许执行请求的最大秒数。只有当compilation元素中的调试属性为False时,此超时属性才适用。默认值为110s。 

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

如果部署到IIS中需要在IIS中加上以下节点:

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

posted @ 2016-10-31 11:36  576  阅读(6131)  评论(1编辑  收藏  举报