Understanding and Resolving the HTTP 413 (Request Entity Too Large) in IIS
Introduction
The “HTTP 413 (Request Entity Too Large)” error is encountered when a client attempts to send a request that exceeds the server’s configured size limit. This is particularly common with large file uploads or extensive data requests. In this blog, we’ll explore the causes of this error in IIS, how to resolve it, and specifically how to adjust configurations for WCF services.
What is the HTTP 413 Error?
The HTTP 413 status code, “Request Entity Too Large,” indicates that the server refuses to process a request because the payload size exceeds the server’s allowable limits. This error typically occurs when sending large files or extensive data in requests.
Why Does the HTTP 413 Error Occur in IIS? IIS has several default limits to protect the server from being overwhelmed by excessively large requests. Common causes include:
Request Filtering Limits: Configured via maxAllowedContentLength in web.config or ApplicationHost.config.
Upload Buffering: Controlled by the uploadReadAheadSize property.
ASP.NET Settings: Managed by maxRequestLength in web.config.
WCF Services: Both service and client configurations need adjustment for large messages.
How to Resolve the HTTP 413 Error in IIS
Adjusting maxAllowedContentLength in web.config
Increase the maximum request size allowed by IIS:
xml
Copy code
<configuration>
<system.webServer>
<security>
<requestFiltering>
<requestLimits maxAllowedContentLength=”52428800″ /> <!– 50 MB and can be adjusted based on the need–>
</requestFiltering>
</security>
</system.webServer>
</configuration>
Modifying uploadReadAheadSize
Configure IIS to handle larger request sizes:
xml
Copy code
<configuration>
<system.webServer>
<serverRuntime uploadReadAheadSize=”10485760″ /> <!– 10 MB and can be adjusted based on the need but has a limit as 2147483647–>
</system.webServer>
</configuration>
Updating maxRequestLength in ASP.NET
For ASP.NET applications, increase the maxRequestLength:
xml
Copy code
<configuration>
<system.web>
<httpRuntime maxRequestLength=”51200″ /> <!– 50 MB –>
</system.web>
</configuration>
Configuring WCF Services (if your WCF is throwing 413 exception)
When dealing with WCF services, especially when both the service and client are hosted on IIS, you need to configure several properties to handle large messages effectively.
Service Configuration:
xml
Copy code
<configuration>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name=”LargeRequestBinding” maxBufferSize=”2147483647″ maxBufferPoolSize=”2147483647″ maxReceivedMessageSize=”2147483647″>
<readerQuotas maxStringContentLength=”2147483647″ maxArrayLength=”2147483647″ maxBytesPerRead=”2147483647″ maxNameTableCharCount=”2147483647″ />
</binding>
</basicHttpBinding>
</bindings>
<services>
<service name=”YourServiceName”>
<endpoint address=”” binding=”basicHttpBinding” bindingConfiguration=”LargeRequestBinding” contract=”IYourService” />
</service>
</services>
</system.serviceModel>
</configuration>
Client Configuration:
xml
Copy code
<configuration>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name=”LargeRequestClientBinding” maxBufferSize=”2147483647″ maxBufferPoolSize=”2147483647″ maxReceivedMessageSize=”2147483647″>
<readerQuotas maxStringContentLength=”2147483647″ maxArrayLength=”2147483647″ maxBytesPerRead=”2147483647″ maxNameTableCharCount=”2147483647″ />
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint address=”http://your-service-url” binding=”basicHttpBinding” bindingConfiguration=”LargeRequestClientBinding” contract=”IYourService” />
</client>
</system.serviceModel>
</configuration>
Explanation:
maxBufferSize and maxBufferPoolSize control the size of the buffers used to process messages.
maxReceivedMessageSize sets the maximum size of messages that can be received.
readerQuotas settings control the maximum size for various aspects of the message to prevent attacks and ensure server stability.
Additional Considerations
If adjusting these configurations does not resolve the issue, please take a memory dump on exception along with WCF Traces. This would help pointing to some issue. Review the configuration thoroughly with correct service names. If you are only working on an ASP.NET web application and trying to upload files larger that 2 GB, then you should consider leveraging WebDav.
Conclusion
The “HTTP 413 (Request Entity Too Large)” error can be managed by configuring IIS and WCF settings to handle larger requests effectively. By understanding and adjusting these settings, you can ensure that your server handles large file uploads and extensive data requests without issues.
Microsoft Tech Community – Latest Blogs –Read More