HTTP Error 413.1 - Request Entity Too Large - How to fix How to resolve the HTTP Error 413.1 - Request Entity Too Large (and similar errors) in an ASP.NET application hosted on IIS Web Server

IIS URL Rewrite: redirect di più nomi di dominio su un singolo hostname

If you have come across this article it is likely that you are trying to configure your ASP.NET application (Core, MVC, Web API, Windows Forms, WCF or other) on an IIS web server which, unlike the development web server , refuses to accept the upload of a file larger than 16kb, returning one of the following errors:

HTTP Error 413.1 - Request Entity Too Large

(413) Request Entity Too Large

Maximum request length exceeded

All these errors are related to exceeding the maximum size of an attachment - or rather, the HTTP Request sent to the server - provided by our ASP.NET application by default. These limitations have been inserted for a valid reason: receiving a file is a rather heavy operation for the server, as it engages a working thread indefinitely. For this reason, the default settings of most ASP.NET applications provide a size generally between 16k and 64k, sufficient for sending / receiving text forms but logically completely inadequate when you need to manage the upload of one or more files.

Luckily enough, solving this problem is quite simple: all we have to do is modify some sections in the application's Web.config file to extend the limits in bytes normally provided for this type of operation. Since these settings vary according to the versions of IIS, we have entered all the versions for which it is necessary to add (or change) the indicated values.

MaxRequestLength

This value sets the maximum length limit of each Request to a maximum of 1073741824 bytes.

IIS (all versions)

IIS (version 7.x and higher)

In addition to the above:

HttpBindings

If your application is a web service built with ASP.NET WFC (SOAP) or Web API / MVC (REST), you also need to add the following attributes to the bindings you intend to use. The best way to proceed is to open the Web.config for the application and, under each of them, add the following highlighted parameters:

The above example has the purpose of increasing the maximum size of any upload up to 2147483647 bytes for all basicHttpBinding connections: depending on the characteristics of your web service and the protocols used, it may be necessary to add the above attributes also to the other bindings present, expected and / or supported: webHttpBinding, wsHttpBinding, customBinding and so on.

In case such addition is not enough to solve the problem, it may be necessary to also change the transferMode attribute, setting it to Streamed (the default is Buffered), and also revise the settings related to the readerQuotas, i.e. the limitations that the server gives to the SOAP clients when initiating their connection:

uploadReadAheadSize

In the event that all the operations described above are not sufficient to solve the problem, all that remains is to try to intervene by changing the value of the uploadReadAheadSize property: unfortunately, this setting cannot be changed at the Web.config level but must be defined directly on the machine hosting the publishing IIS Web Server.

The need to modify this setting is particularly frequent when working with the Windows Communication Foundation (WFC), the (not so much) "modern" method of managing SOAP Web Services that we have already had occasion to talk about in this article: in those scenarios, the problem generally occurs in consequence of any upload larger than 42-49kb.

Let's get to work: access the server using Remote Desktop or physical access, then open a Command Prompt with administrator privileges and type the following command, taking care to replace YOUR_WEBSITE_NAME with the name of the website as you defined it on IIS Manager at the time of creation:

In case you want to operate in a more general way, you can set this new value as a default setting for all websites with the following PowerShell command:

If you prefer to use the GUI, you can also configure these settings via the  Configuration Editor within the Internet Information Services Manager (IISManager) tool:

HTTP Error 413.1 - Request Entity Too Large - How to fix

Once there, select the system.webServer/serverRuntime within the top-left dropdown list, the change the uploadReadAheadSize value to your new desired standard (2147483647 in our example):

HTTP Error 413.1 - Request Entity Too Large - How to fix

IMPORTANT: Make sure the enabled attribute is correctly set to True, otherwise the whole section will not be taken into account and IIS will use the default limitations, blocking uploads larger than 42-49kb.

That's it for now: happy upload!

About Ryan

IT Project Manager, Web Interface Architect and Lead Developer for many high-traffic web sites & services hosted in Italy and Europe. Since 2010 it's also a lead designer for many App and games for Android, iOS and Windows Phone mobile devices for a number of italian companies. Microsoft MVP for Development Technologies since 2018.

View all posts by Ryan

One Comment on “HTTP Error 413.1 - Request Entity Too Large - How to fix How to resolve the HTTP Error 413.1 - Request Entity Too Large (and similar errors) in an ASP.NET application hosted on IIS Web Server

Leave a Reply

Your email address will not be published. Required fields are marked *


The reCAPTCHA verification period has expired. Please reload the page.

This site uses Akismet to reduce spam. Learn how your comment data is processed.