Which gets priority, maxRequestLength or maxAllowedContentLength?
Asked Answered
C

2

139

While changing the maximum allowed file size for upload I stumbled on those two settings.

In the sytem.web you have the http runtime node with maxRequestLength. In the system.webServer you have the requestLimits with maxAllowedContentLength.

Now which gets the priority over the other? And do we need to set both or is the last one (the one for IIS7) enough?

Clinch answered 13/6, 2011 at 7:1 Comment(0)
B
212

maxRequestLength indicates the maximum request size supported by ASP.NET, whereas maxAllowedContentLength specifies the maximum length of content in a request supported by IIS. So you need to set both in order to upload large files: the smaller one "takes priority".

(I picked this up from http://forums.iis.net/t/1169846.aspx -- credit where it's due.)

You can set both to be local to a specific site or even a folder within a site by editing the appropriate web.config file. If the file (well, request) length is less than maxAllowedContentLength but more than maxRequestLength, the user will get your standard (ASPX) error page, if you have one. If it's the other way around, he'll get an IIS error page instead. For that reason, you might want to have maxAllowedContentLength to a very large value (just for this website/folder) and then have the limiting value be maxRequestLength.

Finally, remember that maxRequestLength is in KB whereas maxAllowedContentLength is in BYTES!

Bank answered 24/6, 2011 at 19:10 Comment(1)
I have 3 upload controls in my page where is upload control having a limit of 50 MB. So I am uploading total 150 MB in at one shot, My configuration is maxAllowedContentLength="51200000" & executionTimeout="1200" & maxRequestLength="51200". which length I should be changed here. Please suggest.Suellensuelo
R
24

The short and sweet answer is that the smaller of the two will take precedence. A word of advice though- in my opinion it is advisable to set maxRequestLength to be the smaller of the two as you can catch an exception in the Application_Error event of your Global.asax should it be exceeded. If you exceed maxAllowedContentLength first IIS will deal with it instead of ASP.NET, making it trickier to deal with in code.

Repand answered 25/8, 2011 at 19:41 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.