當上傳一個超過30M的文件時,服務器會重定向至404.13頁面,報錯以下:web
The request filtering module is configured to deny a request that exceeds the request content length.服務器
這是因爲服務器限制了所能上傳文件的最大值。其值在configuration/system.webServer/security/requestFiltering/requestLimits@maxAllowedContentLength setting in the applicationhost.config or web.config file. 中定義。app
查看C:\Windows\System32\inetsrv\config目錄下的applicationhost.config,能夠在system.webServer/security/requestFiltering/中找到requestLimits設置項,若沒有,則能夠自行添加以下:(這裏maxAllowedContentLength的單位爲bytes。)ide
<system.webServer>
<security>
<requestFiltering>
<requestLimits maxAllowedContentLength="40000000" />
</requestFiltering>
<security>
<system.webServer>post
也能夠使用命令行模式修改applicationhost.config爲:this
%windir%\system32\inetsrv\appcmd set config -section:requestFiltering -requestLimits.maxAllowedContentLength:40000000spa
通過這個設置後,服務器對上傳文件的大小限制將變爲40000000bytes了。固然,這個設置是服務器級別的,若是你想在某個站點或者某個應用上限制大小,也能夠經過以相同方式進行設置,只不過此次設置的是站點內的Web.config。命令行
可是你要進行此項修改,要確保applicationhost.config中對該項修改的權限已經放開。可經過以下設置進行更改:code
modify the overrideModeDefault from "Deny" to "Allow" like so:orm
<sectionGroup name="system.webServer">
<section name="requestFiltering" overrideModeDefault="Allow" />
</sectionGroup>
確認修改過applicationhost.config中上述設置之後,再進行以下設置。
找到應用的Web.config,按上述進行修改:
<system.webServer>
<security>
<requestFiltering>
<requestLimits maxAllowedContentLength="40000000" />
</requestFiltering>
<security>
<system.webServer>
或者你也能夠經過命令行的形式:
%windir%\system32\inetsrv\appcmd set config "Default Web Site/<your app>" -section:requestFiltering -requestLimits.maxAllowedContentLength:40000000
這樣,你就能針對某個站點的某個應用進行設置。
可是開發人員是在Web.Config中進行了以下設置:
<system.web>
<httpRuntime maxRequestLength="40960" appRequestQueueLimit="100" useFullyQualifiedRedirectUrl="true" executionTimeout="120" />
</system.web>
這裏的maxRequestLength據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.
可是開發人員的這個設置好像是不起做用的。他們在這裏,限制最大請求長度爲40MB,超時爲120s。
下次再看一下具體這個設置是用來作什麼的。
-------------------------
如今明白了。這個是用來設置單個請求的最大長度。好比EmailTicket中若設置maxRequestLength爲30M,maxAllowedContentLength爲40M,
而後在Reply Email時,選擇了一個35M的附件,在點擊Save as Draft的時候,這個請求的長度大概會有35M,這個已經超過了maxRequestLength。此時請求就會報錯了,結果是黃頁:
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Web.HttpException: Maximum request length exceeded.
因此,最好是maxRequestLength和maxAllowedContentLength設置爲一致的值。