skip to Main Content

I have an older ASP.NET API web service using .net 4.5.2 and I am posting an object that contains a base64 image to my controller without any problem. The issues come now when I try to post data with more and larger images and I am getting the 413 request entity too large error. I have been looking up things and tried everything I could find on the net with no luck. I am looking to upload files about 10MB in size. One thing that leads me to believe its server related is when running the service under IIS Express I can upload large files locally.

I have tried adding MaxRequestLength and MaxAllowableContentLength to the web config.

<system.web>
    <!-- tell IIS to let large requests through -->
    <httpRuntime maxRequestLength="52428800" />

<system.webServer>
    <security>
        <requestFiltering>
            <requestLimits maxAllowedContentLength="52428800" />
        </requestFiltering>
    </security>

I have also made a change on my windows 2012 R2 server in IIS v6.2 to allow larger files. I have also adjusted the UploadReadAhead value on the server.

enter image description here

enter image description here

enter image description here

I don’t have anything special in API config class.

public static class WebApiConfig
{
    public static void Register(HttpConfiguration config)
    {
        config.MapHttpAttributeRoutes();

        config.Routes.MapHttpRoute(
            name: "DefaultApi",
            routeTemplate: "api/{controller}/{id}",
            defaults: new { id = RouteParameter.Optional }
        );

        var appXmlType = config.Formatters.XmlFormatter.SupportedMediaTypes.FirstOrDefault(t => t.MediaType == "application/xml");
        config.Formatters.XmlFormatter.SupportedMediaTypes.Remove(appXmlType);
    }
}

The bindings in my config for this service

    <webHttpBinding>
        <binding name="SecureServerBindingWithUserNameRest"  maxReceivedMessageSize="52428800">
            <readerQuotas maxArrayLength="10485760" />
                <security mode="TransportCredentialOnly">
                <transport clientCredentialType="Basic" proxyCredentialType="None" />
            </security>
        </binding>
        <binding name="webHttpTransportSecurityRest">
            <security mode="Transport" />
        </binding>
    </webHttpBinding>

3

Answers


  1. You can try this solution, try to increase the upload size limit. IIS uses uploadReadAheadSize parameter in applicationHost.config and web.config files.

    1. Open IIS Manager
    2. Select the site
    3. Double click "Configuration Editor"
    4. Select system.webServer and then serverRuntime
    5. Modify the uploadReadAheadSize value to 2147483647
    6. Click "Apply"
    Login or Signup to reply.
  2. You might also consider executing a dummy get request just before posting large content. When a https connection is initialized, this first request should not be very large. Once the https connection is initialized proceeding requests are not limitted.

    Login or Signup to reply.
  3. When I encountered this error while sendig zipped files containing a large amount of PDFS, the solution I found was to also add to the web config requestLengthDiskThreshold apart from the maxRequestLength:

    <system.web>
        <httpRuntime maxRequestLength="268435456" requestLengthDiskThreshold="268435456" executionTimeout="600"/>
    

    I also added a longer timeout than the 90 preset so it had time to send the file. Just have in mind that the requestLengthDiskThreshold must not exceed the maxRequestLength.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search