當上傳一個超過30M的文件時,服務器會重定向至404.13頁面,報錯如下:
這是由于服務器限制了所能上傳文件的最大值。其值在configuration/system.webServer/security/requestFiltering/requestLimits@maxAllowedContentLength setting in the applicationhost.config or web.config file. 中定義。
查看C:\Windows\System32\inetsrv\config目錄下的applicationhost.config,可以在system.webServer/security/requestFiltering/中找到requestLimits設置項,若沒有,則可以自行添加如下:(這里maxAllowedContentLength的單位為bytes。)
<system.webServer>
<security>
<requestFiltering>
<requestLimits maxAllowedContentLength="40000000" />
</requestFiltering>
<security>
<system.webServer>
也可以使用命令行模式修改applicationhost.config為:
%windir%\system32\inetsrv\appcmd set config -section:requestFiltering -requestLimits.maxAllowedContentLength:40000000
經(jīng)過這個設置后,服務器對上傳文件的大小限制將變?yōu)?0000000bytes了。當然,這個設置是服務器級別的,如果你想在某個站點或者某個應用上限制大小,也可以通過以相同方式進行設置,只不過這次設置的是站點內(nèi)的Web.config。
但是你要進行此項修改,要確保applicationhost.config中對該項修改的權(quán)限已經(jīng)放開??赏ㄟ^如下設置進行更改:
modify the overrideModeDefault from "Deny" to "Allow" like so:
<sectionGroup name="system.webServer">
<section name="requestFiltering" overrideModeDefault="Allow" />
</sectionGroup>
確認修改過applicationhost.config中上述設置以后,再進行如下設置。
找到應用的Web.config,按上述進行修改:
<system.webServer>或者你也可以通過命令行的形式:
%windir%\system32\inetsrv\appcmd set config "Default Web Site/<your app>" -section:requestFiltering -requestLimits.maxAllowedContentLength:40000000
這樣,你就能針對某個站點的某個應用進行設置。
但是開發(fā)人員是在Web.Config中進行了如下設置:
<system.web>
<httpRuntime maxRequestLength="40960" appRequestQueueLimit="100" useFullyQualifiedRedirectUrl="true" executionTimeout="120" />
</system.web>
這里的maxRequestLength據(jù)MSDN介紹:Gets or sets the maximum request size. The maximum request size in kilobytes. The default size is 4096 KB (4 MB).
The MaxRequestLength property specifies the limit for the buffering threshold of the input stream. For example, this limit can be used to prevent denial of service attacks(拒絕服務攻擊) that are caused by users who post large files to the server.
The value assigned to this property should be greater or equal to value assigned to the RequestLengthDiskThreshold property.
但是開發(fā)人員的這個設置好像是不起作用的。他們在這里,限制最大請求長度為40MB,超時為120s。
下次再看一下具體這個設置是用來做什么的。
-------------------------
現(xiàn)在明白了。這個是用來設置單個請求的最大長度。比如EmailTicket中若設置maxRequestLength為30M,maxAllowedContentLength為40M,
然后在Reply Email時,選擇了一個35M的附件,在點擊Save as Draft的時候,這個請求的長度大概會有35M,這個已經(jīng)超過了maxRequestLength。此時請求就會報錯了,結(jié)果是黃頁:
所以,最好是maxRequestLength和maxAllowedContentLength設置為一致的值。