Handling files uploaded larger than maxRequestLength in web.config

In my web.config, my file upload size is limited to 10 MB:

<httpRuntime maxRequestLength="10000" /> <!-- file size limit in KB --> 

On my page, I verify that the user does not upload a file larger than 5 MB:

 protected void cvImageSize_ServerValidate(object source, ServerValidateEventArgs args) { args.IsValid = (fupFile.PostedFile.InputStream.Length <= 5000000); } 

If a user tries to download a 3 MB file, he downloads everything. If a user tries to download a 7 MB file, a cvImageSize error message is displayed.

If a user tries to upload a file of 13 MB in size ... the site crashes. I'm not sure what is happening, Firefox gives me a page with the message "The connection was reset. The connection to the server was reset while the page was loading. "

Is there any exception that I can catch when a user tries to upload a file with a size larger than maxRequestLength? I would like to show the user an error message on the page, and not just a website crash.

+4
source share
2 answers

There is also an IIS execution timeout - this can cause problems. You can increase this value. For more information, check out this article: http://aspnetresources.com/articles/dark_side_of_file_uploads

+4
source

The main problem is that the "check" (cvImageSize_ServerValidate) actually happens on the server. This means that the file must be downloaded first for your server-side code so that it can be checked.

Therefore, when a larger file is loaded (web.config file), the server throws an exception and your code never gets the opportunity to check. No matter how you quit, the user will still have to upload the file to his server first in order to file complaints with the server or to check the size.

If you cannot use Html5 (and compatible browsers) Download the Html5 file

0
source

All Articles