設(shè)置IIS7文件上傳的最大大小 maxAllowedContentLength,maxRequestLength
發(fā)布日期:2022/7/4 15:15:08 瀏覽量:
當(dāng)上傳一個超過30M的文件時,服務(wù)器會重定向至404.13頁面,報錯以下:web
HTTP Error 404.13 - Not Found
The request filtering module is configured to deny a request that exceeds the request content length.服務(wù)器
這是因?yàn)榉?wù)器限制了所能上傳文件的最大值。其值在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設(shè)置項(xiàng),若沒有,則能夠自行添加以下:(這里maxAllowedContentLength的單位為bytes。)ide
<system.webServer>
<security>
<requestFiltering>
<requestLimits maxAllowedContentLength="40000000" />
</requestFiltering>
<security>
<system.webServer>post
也能夠使用命令行模式修改applicationhost.config為:
%windir%\system32\inetsrv\appcmd set config -section:requestFiltering -requestLimits.maxAllowedContentLength:40000000
通過這個設(shè)置后,服務(wù)器對上傳文件的大小限制將變?yōu)?0000000bytes了。固然,這個設(shè)置是服務(wù)器級別的,若是你想在某個站點(diǎn)或者某個應(yīng)用上限制大小,也能夠經(jīng)過以相同方式進(jìn)行設(shè)置,只不過此次設(shè)置的是站點(diǎn)內(nèi)的Web.config。命令行
可是你要進(jìn)行此項(xiàng)修改,要確保applicationhost.config中對該項(xiàng)修改的權(quán)限已經(jīng)放開。可經(jīng)過以下設(shè)置進(jìn)行更改:code
modify the overrideModeDefault from "Deny" to "Allow" like so:orm
<sectionGroup name="system.webServer">
<section name="requestFiltering" overrideModeDefault="Allow" />
</sectionGroup>
確認(rèn)修改過applicationhost.config中上述設(shè)置之后,再進(jìn)行以下設(shè)置。
找到應(yīng)用的Web.config,按上述進(jìn)行修改:
<system.webServer>
<security>
<requestFiltering>
<requestLimits maxAllowedContentLength="40000000" />
</requestFiltering>
<security>
<system.webServer>
或者你也能夠經(jīng)過命令行的形式:
%windir%\system32\inetsrv\appcmd set config "Default Web Site/<your app>" -section:requestFiltering -requestLimits.maxAllowedContentLength:40000000
這樣,你就能針對某個站點(diǎn)的某個應(yīng)用進(jìn)行設(shè)置。
可是開發(fā)人員是在Web.Config中進(jìn)行了以下設(shè)置:
<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(拒絕服務(wù)攻擊) 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ā)人員的這個設(shè)置好像是不起做用的。他們在這里,限制最大請求長度為40MB,超時為120s。
下次再看一下具體這個設(shè)置是用來作什么的。
-------------------------
如今明白了。這個是用來設(shè)置單個請求的最大長度。好比EmailTicket中若設(shè)置maxRequestLength為30M,maxAllowedContentLength為40M,
而后在Reply Email時,選擇了一個35M的附件,在點(diǎn)擊Save as Draft的時候,這個請求的長度大概會有35M,這個已經(jīng)超過了maxRequestLength。此時請求就會報錯了,結(jié)果是黃頁:
Server Error in ’/emailticket’ Application.
Maximum request length exceeded.
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設(shè)置為一致的值。
馬上咨詢: 如果您有業(yè)務(wù)方面的問題或者需求,歡迎您咨詢!我們帶來的不僅僅是技術(shù),還有行業(yè)經(jīng)驗(yàn)積累。
QQ: 39764417/308460098 Phone: 13 9800 1 9844 / 135 6887 9550 聯(lián)系人:石先生/雷先生