在IIS7及以上运行时,还有另一个参数:
<system.webServer>
<security>
<requestFiltering>
<requestLimits maxAllowedContentLength="10485760" />
</requestFiltering>
</security>
</system.webServer>
默认设置略小于30 MB.
对于大小在maxRequestLength
到maxAllowedContentLength
之间的上传文件,IIS7将抛出一个HttpException
,HTTP代码为500,消息文本为Maximum request length exceeded
.当引发此异常时,IIS7会立即终止连接.因此,仅当在global.asax.cs的Application_Error()
中处理并清除了HttpException
(使用Server.ClearError()
)时,重定向到此错误的HttpModule
才能工作.
对于大小大于maxAllowedContentLength
的上载文件,IIS7将显示详细的错误页面,错误代码为404和subStatusCode
13.错误页面可在C:\inetpub\stemerr\en-US\404-13.htm中找到
对于IIS7上此错误的重定向,我建议改为在httpErrors
上重定向.
<system.webServer>
<httpErrors errorMode="Custom" existingResponse="Replace">
<remove statusCode="404" subStatusCode="13" />
<error statusCode="404" subStatusCode="13" prefixLanguageFilePath=""
path="http://yoursite.com/Error/UploadTooLarge" responseMode="Redirect" />
</httpErrors>
</system.webServer>