I’ve got an MVC3 website that allows users to upload images. If a user tries uploading an image that is greater than the allowed value in my web.config, they are given a 404 response. I’m using a FileUpload control. The user is getting 404 response when they submit the form and the file is too large.
Here is an article discussing how to fix the problem, but it only explains how to increase the max size of the file. I don’t want to increase the size, but rather give the user a friendly message when they do.
I’d like to intercept this response before it returns, so I can give them a friendly message explaining why they can’t upload the file.
Is this possible?
Is an exception being thrown that you can grab during the Application_Error event in the global.asax?
I’m not sure what this particular FileUpload control is that you mention, but with a plain MVC3 application, when I upload a file the Visual Studio web server (“cassini”) responds with a 504 error. The framework throws an HttpException when an uploaded file is too large. You could catch it like so:
This article is a good reference for the perils of large file uploads: http://weblogs.asp.net/jgalloway/archive/2008/01/08/large-file-uploads-in-asp-net.aspx