IIS Large File Upload Error
So you want to let someone upload something to your server using ASP.NET MVC. Not a big problem, pretty simple. But what happens if someone tries to upload a large file?

The default max upload file size is four megabytes. Anything larger and you receive that message. Of course you could set the maxRequestLength in the web.config but the problem with that is that we didn’t deal with the problem.
We don’t just want to put the problem out of mind and hope that no one uploads more than that, but we want to have some control over how much someone can upload to our server and if they try to upload more than our limit handle it properly.
This is the basic settings for the webconfig to handle a 404.13 error.
<system.webServer> <httpErrors errorMode="Custom" existingResponse="Replace"> <error statusCode="404" subStatusCode="13" path="/Home/Error" responseMode="Redirect" /> </httpErrors> </system.webServer>
There are some additional settings and information available on Display custom error page when file upload exceeds allowed size in ASP.NET MVC.
But there is just one problem, it doesn’t work. Well it does. Just not with Visual Studio development server.
To fix the issue either run the site under IIS proper or just set Visual Studio to use IIS Express by right clicking the project name and select the option from the context menu.

After that run the project and try to upload a file larger than four megabytes (or whatever you set it to) and you should receive your custom error page.

Leave a Reply