Search code examples
c#asp.net-web-apiodatafiddler

What is limit of Post in Fiddler or C#


I'm trying to test why my server is responding with 500 error when I send a large image (627 kb) as binary from the client. So, I brought the values the client sent in fiddler in the same machine the server is at. I kept increasing & decreasing the number of binary value. I'm marking the beginning of the post method with a break point and then at every test I check the object if it is null or not: enter image description here

the entity has a property for value called: ImageDataString of type string, which houses the binary values.

I noticed that if I increase 1 more character to my post at the arrow in fiddler, the object becomes null enter image description here

Whose limit is invalidating the post request, Fiddler or C# OData Api? In fact my image body is much more than those lengths. It can be up to 10 mg, what should I do to send large images and be able to test sending their binaries in fiddler!?


Solution

  • Your request is probably exceeding the maximum content length limit of IIS. Adjust it in your Web.config:

    <configuration>
        <system.web>
            <httpRuntime maxRequestLength="<upper limit in KB>" />
        </system.web>
    </configuration>
    

    For IIS versions >=7 you have to configure this value as well:

     <system.webServer>
       <security>
          <requestFiltering>
             <requestLimits maxAllowedContentLength="<upper limit in Bytes>" />
          </requestFiltering>
       </security>
     </system.webServer>
    

    Another problem you might run into is that the base 64 decoding could fail if you added random characters to the request body.

    When you encode data with base 64 the output string will be padded to have a length divisible by 3. If you add a random character to the base 64 string the padding will be wrong and thus the decoding will fail.

    If that is the case then the server will throw a FormatException with the message "Invalid length for a Base-64 char array or string." internally which in turns results in the HTTP status code 500 (Internal server error).