如何在IIS7上运行时将maxAllowedContentLength设置为500MB?

Amr*_*rhy 84 asp.net iis-7 file-upload .net-4.0

我将maxAllowedContentLength更改为

<security>
    <requestFiltering>
        <requestLimits maxAllowedContentLength="5024000000" />
    </requestFiltering>
</security>
Run Code Online (Sandbox Code Playgroud)

在我的web.config中,但在IIS7上运行时出现此错误:

'maxAllowedContentLength'属性无效.不是有效的无符号整数

http://i.stack.imgur.com/u1ZFe.jpg

但是当我在VS服务器中运行时,它正常运行而没有任何错误.

如何配置我的网站允许上传500MB大小的文件,在IIS7上没有这个问题?

小智 124

.Net中的请求限制可以从两个属性配置在一起:

第一

  • Web.Config/system.web/httpRuntime/maxRequestLength
  • 计量单位:千字节
  • 默认值4096 KB(4 MB)
  • 最大.值2147483647 KB(2 TB)

第二

  • Web.Config/system.webServer/security/requestFiltering/requestLimits/maxAllowedContentLength (以字节为单位)
  • 度量单位:字节
  • 默认值30000000字节(28.6 MB)
  • 最大.值4294967295字节(4 GB)

参考文献:http : //www.whatsabyte.com/P1/byteconverter.htm https://www.iis.net/configreference/system.webserver/security/requestfiltering/requestlimits

例:

<location path="upl">
   <system.web>
     <!--The default size is 4096 kilobytes (4 MB). MaxValue is 2147483647 KB (2 TB)-->
     <!-- 100 MB in kilobytes -->
     <httpRuntime maxRequestLength="102400" />
   </system.web>
   <system.webServer>
     <security>
       <requestFiltering>          
         <!--The default size is 30000000 bytes (28.6 MB). MaxValue is 4294967295 bytes (4 GB)-->
         <!-- 100 MB in bytes -->
         <requestLimits maxAllowedContentLength="104857600" />
       </requestFiltering>
     </security>
   </system.webServer>
 </location>
Run Code Online (Sandbox Code Playgroud)

  • 非常有帮助,但我相信maxAllowedContentLength的最大值大约是4 GB,而不是4 TB (4认同)

aba*_*hev 89

根据MSDN的 maxAllowedContentLength类型uint,其最大值为4,294,967,295字节= 3,99 gb

所以它应该工作正常.

另请参阅" 请求限制"一文.当没有配置相应的部分时,IIS是否会返回其中一个错误?

另请参阅:超出最大请求长度

  • 5024000000> 4294967295 (15认同)
  • 500MB = 524288000,现在小于4294967295 (2认同)

Leg*_*nds 13

IIS v10(但这对于 IIS 7.x 也应该相同)

为正在寻找各自最大值的人快速添加

最大的maxAllowedContentLength是:UInt32.MaxValue 4294967295 bytes~4GB

最大的maxRequestLength是:Int32.MaxValue 2147483647 bytes~2GB

网页配置

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <system.web>
    <!-- ~ 2GB -->
    <httpRuntime maxRequestLength="2147483647" />
  </system.web>
  <system.webServer>
    <security>
      <requestFiltering>
        <!-- ~ 4GB -->
        <requestLimits maxAllowedContentLength="4294967295" />
      </requestFiltering>
    </security>
  </system.webServer>
</configuration>
Run Code Online (Sandbox Code Playgroud)