4

In my web.config, I have the file upload size limited to 10 MB:

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

On my page, I'm checking to see that the user doesn't 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 upload a 3 MB file, it uploads fine. If a user tries to upload a 7 MB file, they are shown the error message from cvImageSize.

If a user tries to upload a 13 MB file...the site crashes. I'm not sure exactly what happens, Firefox gives me the page saying "The connection was reset. The connection to the server was reset while the page was loading."

Is there some exception I can catch when the user tries to upload a file with a size greater than the maxRequestLength? I'd like to show the user an error message on the page instead of the site basically crashing.

2

2 Answers 2

4

There is also an IIS execution timeout - which may be causing your issue. You can raise that value as well. For more info, check out this article: http://aspnetresources.com/articles/dark_side_of_file_uploads

Sign up to request clarification or add additional context in comments.

Comments

0

Your basic issue is that the "validation" (cvImageSize_ServerValidate) is really happening on the server. That means the file has to be uploaded first for your server side code to be able to validate.

So when a larger (the web.config setting) file is uploaded the server throws an exception and your code never gets a chance to validate. No matter how you dice it, the user will still have to upload the file to your server first for either the server to complain or for you to validate the size.

Unless you're able to use Html5 (and browsers that are compatible) Html5 File Upload with Progress

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.