Asp.net

如何在 IIS7 上執行時將 maxAllowedContentLength 設置為 500MB?

  • October 26, 2010

我將 maxAllowedContentLength 更改為

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

在我的 web.config 中,但在 IIS7 上執行時出現此錯誤:

“maxAllowedContentLength”屬性無效。不是有效的無符號整數

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

但是當我在 VS 伺服器中執行時,它執行正常,沒有任何錯誤。

如何配置我的網站以允許上傳大小為 500MB 的文件,而在 IIS7 上沒有此問題?

根據MSDN maxAllowedContentLength has type uint,它的最大值是 4,294,967,295 bytes = 3,99 gb

所以它應該可以正常工作。

另請參閱請求限製文章。如果根本沒有配置相應的部分,IIS 是否會返回這些錯誤之一?

另請參閱:超出最大請求長度

.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>

例子:

&lt;location path="upl"&gt;
  &lt;system.web&gt;
    &lt;!--The default size is 4096 kilobytes (4 MB). MaxValue is 2147483647 KB (2 TB)--&gt;
    &lt;!-- 100 MB in kilobytes --&gt;
    &lt;httpRuntime maxRequestLength="102400" /&gt;
  &lt;/system.web&gt;
  &lt;system.webServer&gt;
    &lt;security&gt;
      &lt;requestFiltering&gt;          
        &lt;!--The default size is 30000000 bytes (28.6 MB). MaxValue is 4294967295 bytes (4 GB)--&gt;
        &lt;!-- 100 MB in bytes --&gt;
        &lt;requestLimits maxAllowedContentLength="104857600" /&gt;
      &lt;/requestFiltering&gt;
    &lt;/security&gt;
  &lt;/system.webServer&gt;
&lt;/location&gt;

引用自:https://stackoverflow.com/questions/4022434