c# Asp Web API: HttpException: Maximum request length exceeded.

moondaddy 911 Reputation points
2021-08-26T08:27:19.473+00:00

This might be a common question, but my situation is not so common.

I an sending a serialized image into an Asp.net Web API method and am getting this error:

System.Web.HttpException: Maximum request length exceeded.

at System.Web.HttpBufferlessInputStream.ValidateRequestEntityLength()

I searched online and found a lot of answers saying to do this in the web.config:

<system.web>
  <httpRuntime maxRequestLength="40960" /> // 40MB (default)
</system.web>

<system.webServer>
  <security>
    <requestFiltering>
      <requestLimits maxAllowedContentLength="2147483648" /> // 2GB
    </requestFiltering>
  </security>
</system.webServer>

but when I do that all of my other API calls fail. I get:

500 - Internal server error.

and no code executes in the API calls. they all fail.

So I cannot use this setting to allow bigger files to be send into the API.

What should I do?

thanks.

C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,204 questions
ASP.NET API
ASP.NET API
ASP.NET: A set of technologies in the .NET Framework for building web applications and XML web services.API: A software intermediary that allows two applications to interact with each other.
293 questions
{count} votes