Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.net HTTP 404 - File not found instead of MaxRequestLength exception

I have a file upload control on my webpage. The maximum request length is set to 8 MB (maxRequestLength = 8192). I also have server validation that throws an error if the file is more than 4MB. The reason that its 8MB in the config is the leverage that's given to the user and also so that the application can be tested.

If I upload a file that's 9MB, I get thrown an exception Maximum request length exceeded., which is fine and working as expected. But when I try to upload a file that's 1GB, it shows me a HTTP 404 - File not found. Can someone please explain why this is happening and how can I get it to throw me a maxRequestLength exception?

I'm using IIS6.

like image 427
Divi Avatar asked Jan 19 '11 02:01

Divi


2 Answers

I experienced this condition today (HTTP 404 on large file upload with IIS 7) but I thought I had made all the correct configuration settings. I wanted to upload files up to 300MB so I made the following web.config settings in a sub-folder of the application:

<configuration>     <system.web>         <httpRuntime maxRequestLength="307200" />     </system.web>     <system.webServer>         <security>             <requestFiltering>                 <requestLimits maxAllowedContentLength="314572800" />             </requestFiltering>         </security>     </system.webServer> </configuration> 

This configuration worked in test but when I copied the updated files including the web.config to the production server, I received the HTTP 404 error on uploading a 90MB file. Smaller files under the application-wide limit of 30MB were working fine, so I knew it was a request size problem of some sort.

I figured there was a chance IIS had cached some application settings and just hadn't updated them, so I recycled the Application Pool, after which everything worked as expected.

like image 155
pseudocoder Avatar answered Sep 20 '22 02:09

pseudocoder


I feel none of the answers here explain why you get a 404, they just tell you the usual stuff of how to fix the problem.

The 404 is not due to misconfiguration, it is intentional and documented behaviour:

When request filtering blocks an HTTP request because an HTTP request exceeds the request limits, IIS 7 will return an HTTP 404 error to the client and log one of the following HTTP statuses with a unique substatus that identifies the reason that the request was denied:

 HTTP Substatus    Description  404.13            Content Length Too Large 404.14            URL Too Long 404.15            Query String Too Long 

These substatuses allow Web administrators to analyze their IIS logs and identify potential threats.

In addition, when an HTTP request exceeds the header limits that are defined in the in the <headerLimits> element, IIS 7 will return an HTTP 404 error to the client with the following substatus:

 HTTP Substatus    Description  404.10            Request Header Too Long 
like image 33
user247702 Avatar answered Sep 23 '22 02:09

user247702