I’m writing an upload function, and have problems catching ‘System.Web.HttpException: Maximum request length exceeded’ with files larger than the specified max size in httpRuntimein web.config (max size set to 5120). I’m using a simple <input> for the file.
The problem is that the exception is thrown before the upload button’s click-event, and the exception happens before my code is run. So how do I catch and handle the exception?
EDIT: The exception is thrown instantly, so I’m pretty sure it’s not a timeout issue due to slow connections.
There is no easy way to catch such exception unfortunately. What I do is either override the OnError method at the page level or the Application_Error in global.asax, then check if it was a Max Request failure and, if so, transfer to an error page.
It’s a hack but the code below works for me