Click here to Skip to main content
15,867,686 members
Articles / Web Development / IIS

(413) Request Entity Too Large

Rate me:
Please Sign up or sign in to vote.
4.85/5 (12 votes)
13 Jan 2013CPOL2 min read 193.7K   17   20
A solution to the problem

Recently I worked with a WCF web service that is hosted in IIS7, and I used one of the service methods to send a byte array that contains a picture. This works well with small size images, but when I am trying to upload a larger picture, the WCF service returns an error: (413) Request Entity Too Large. I got the same error a month ago when I was developing an ASP.NET web application that is hosted on IIS 7 over SSL. In that case, there was no file upload on the page. It occurred when I am accessing the web pages that are having a grid view control with a large amount of pagination. The same pages worked fine on HTTP but not on HTTPS. In both scenarios, I Googled and found out different solutions.

1. uploadReadAheadSize

In the second scenario, the error occurred because of the size of the page, it is very big, and it caused to request entry body become larger when you are submitting the page.

What happens is if you have a website with SSL and "Accept Client Certificates" enabled, HTTP requests are limited to the UploadReadAheadSize of the site. To resolve this, you have to increase the UploadReadAheadSize (Default size 48kb).

appcmd.exe set config -section:system.webserver/serverruntime 
/uploadreadaheadsize: 1048576 /commit:apphost

2. maxReceivedMessageSize

WCF by default limits messages to 64KB to avoid DOS attack with a large message. By default, it sends byte[] as base64 encoded string, and it increases the size of the message (33% increase in size). Therefore, if the uploaded file size is ~larger than 48KB, then it raises the above error. (48KB * 1.33 = ~64KB) (N.B.: you can use MTOM – Message Transmission Optimization Mechanize to optimize the message)

By modifying the "maxReceivedMessageSize" in the Web.config file to accept large messages, you can solve this issue.

XML
<system.serviceModel>
  <bindings>
    <basicHttpBinding>
      <binding maxReceivedMessageSize="10485760">
        <readerQuotas ... />
      </binding>
    </basicHttpBinding>
  </bindings>  
</system.serviceModel>

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Technical Lead Eyepax IT Consulting (Pvt) Ltd.
Sri Lanka Sri Lanka
Having more than 9 year hands-on industry experience in software development
Responsible for designing, implementing and managing complex software systems with stringent up-time requirement.

Visit my blog

Comments and Discussions

 
QuestionThanks Pin
Alejandro Castrejon 20227-Jan-22 9:06
Alejandro Castrejon 20227-Jan-22 9:06 
QuestionThanks Pin
Member 36756047-Sep-17 6:38
Member 36756047-Sep-17 6:38 
QuestionHello Tharaka MTR, I still the problem. 413 Request Entity Too Large Pin
Member 1098845319-May-15 4:33
Member 1098845319-May-15 4:33 
QuestionStill got the problem Pin
Member 1054058626-Aug-14 0:14
Member 1054058626-Aug-14 0:14 
QuestionI already stated in the article but I still have the error 413 Pin
raijuli16-Jul-14 6:45
raijuli16-Jul-14 6:45 
AnswerRe: I already stated in the article but I still have the error 413 Pin
Tharaka MTR19-Jul-14 1:08
professionalTharaka MTR19-Jul-14 1:08 
QuestionStill error Pin
♥…ЯҠ…♥7-Aug-13 0:21
professional♥…ЯҠ…♥7-Aug-13 0:21 
AnswerRe: Still error Pin
Tharaka MTR7-Aug-13 1:01
professionalTharaka MTR7-Aug-13 1:01 
GeneralRe: Still error Pin
♥…ЯҠ…♥7-Aug-13 18:51
professional♥…ЯҠ…♥7-Aug-13 18:51 
GeneralRe: Still error Pin
Tharaka MTR9-Aug-13 0:16
professionalTharaka MTR9-Aug-13 0:16 
Answer413 error solution work for me Pin
rajkiran3-Aug-13 2:23
rajkiran3-Aug-13 2:23 
GeneralRe: 413 error solution work for me Pin
Tharaka MTR4-Aug-13 3:35
professionalTharaka MTR4-Aug-13 3:35 
Questionyou saved my time Pin
Member 80626319-Jul-13 1:37
Member 80626319-Jul-13 1:37 
AnswerRe: you saved my time Pin
Tharaka MTR9-Jul-13 23:09
professionalTharaka MTR9-Jul-13 23:09 
GeneralMy vote of 4 Pin
Marco Bertschi14-Jan-13 3:16
protectorMarco Bertschi14-Jan-13 3:16 
GeneralRe: My vote of 4 Pin
Tharaka MTR14-Jan-13 5:19
professionalTharaka MTR14-Jan-13 5:19 
GeneralMy vote of 3 Pin
arbinda_dhaka13-Jan-13 9:17
arbinda_dhaka13-Jan-13 9:17 
GeneralRe: My vote of 3 Pin
Tharaka MTR13-Jan-13 15:35
professionalTharaka MTR13-Jan-13 15:35 
GeneralMy vote of 5 Pin
Thornik8-Jan-13 5:34
Thornik8-Jan-13 5:34 
GeneralRe: My vote of 5 Pin
Tharaka MTR13-Jan-13 15:36
professionalTharaka MTR13-Jan-13 15:36 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.