Net上传文件大小配置

1、起因

  今天同事在上传文件的时候,发现一直失败,说文件比较大。一听就明白了,肯定是上传文件大小的问题啊。然后查看web.config文件,发现设置过文件上传的大小限制。配置文件上传大小,分为2部分。

 <httpRuntime maxRequestLength="1073741824"   executionTimeout="3600" useFullyQualifiedRedirectUrl="true" requestValidationMode="2.0" />

2、web.config级设置

  此处的maxRequestLength设置是.net级的设置,单位是KB

 <httpRuntime maxRequestLength="1073741824"   executionTimeout="3600" useFullyQualifiedRedirectUrl="true" requestValidationMode="2.0" />

3、IIS服务器级设置

  这里有2种方式:

  1)iis管理器端设置,找到自己的网站。前提是在安装iis的时候,有安装请求筛选,如下图。然后选择请求筛选,编辑功能设置,把允许的最大内容长度更改为所需要的大小,注意这里单位是字节。这里确定后,iis会自动在web.config中添加一段代码。这也是下面要介绍的第2种方式。

  2)在web.config中的system.webServer中添加配置。注意,单位是字节。

    <security>
            <requestFiltering>
                <requestLimits maxAllowedContentLength="8703144" />
            </requestFiltering>
        </security>

参考文档:

  https://stackoverflow.com/questions/6327452/which-gets-priority-maxrequestlength-or-maxallowedcontentlength

  https://forums.asp.net/t/1965933.aspx?increase+upload+limit+system+webServer+security+requestFiltering+requestLimits+maxAllowedContentLength+10485760+requestFiltering+security+system+webServer+

猜你喜欢

转载自www.cnblogs.com/niyl/p/9578558.html