ASP.NET中maxRequestLength和maxAllowedContentLength的區別

maxRequestLength表示ASP支持的最大請求大小,而maxAllowedContentLength指定IIS支持的請求中內容的最大長度。因此,要上傳大文件,我們需要同時設置這兩個參數:較小的那個“優先”,即最終支持上傳的文件的大小根據maxRequestLength和maxAllowedContentLength中的較小值而定。
如果文件長度小於maxAllowedContentLength但大於maxRequestLength,用戶將獲得標準(ASPX)錯誤頁面。相反,用戶會得到IIS錯誤頁面。

HTTP Error 404.13 - Not Found

The request filtering module is configured to deny a request that exceeds the request content length.

需要在web.config中配置如下:

<system.web>

<httpRuntime requestValidationMode="2.0" maxRequestLength="3072" ></httpRuntime>

<!--單位:KB 3072=3MB 默認是4MB,最大支持2GB-->

</system.web>

<system.webServer>

<security>
<requestFiltering>
<requestLimits maxAllowedContentLength="2147483648" />
<!--單位:字節B 2147483648=2 GB 默認是4MB,最大支持2GB-->
</requestFiltering>
</security>

</system.webServer>

 

最後,需要注意的是,maxRequestLength的單位是KB,而maxAllowedContentLength的單位是字節,既然是請求,那麼指的不僅僅是上傳文件,只要是用戶發送的請求,都可以通過上面的配置限制,比如Ajax請求服務器接口,參數內容超過了設置的最大長度就會請求失敗

 

Stack Overflow 上的問答:asp.net - How to set the maxAllowedContentLength to 500MB while running on IIS7? - Stack Overflow
————————————————
版權聲明:本文爲CSDN博主「Tanjia_kiki」的原創文章
原文鏈接:https://blog.csdn.net/qq_23663693/article/details/89920039

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章