413 content to large for .net core

Paras Panchal 20 Reputation points
2025-04-24T10:04:51.1066667+00:00

I have an API endpoint that accepts a multipart/form-data request containing 10 files along with some additional form fields. This works perfectly in my local development environment where I’ve configured Kestrel to allow unlimited request body size (MaxRequestBodySize = null).

However, when deployed to IIS, I encounter a 413 Payload Too Large error. I’m aware that I can increase the request size limit in the IIS settings (e.g., maxAllowedContentLength, maxRequestLength), but I would prefer not to change the global settings since that could affect other endpoints and introduce potential risks.

Is there a way to configure IIS or the .NET Core application to allow larger request sizes only for this specific endpoint without impacting others?

Any guidance or best practices would be greatly appreciated.

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.
11,431 questions
0 comments No comments
{count} votes

Accepted answer
  1. SurferOnWww 4,391 Reputation points
    2025-04-25T02:11:53.2333333+00:00

    Is there a way to configure IIS or the .NET Core application to allow larger request sizes only for this specific endpoint without impacting others?

    If you deployed your ASP.NET Core app to IIS properly, the web.config was automatically generated and included under the site root as shown below;

    enter image description here

    The code of web.config is something like below:

    <?xml version="1.0" encoding="utf-8"?>
    <configuration>
      <location path="." inheritInChildApplications="false">
        <system.webServer>
          <handlers>
            <add name="aspNetCore" path="*" verb="*" 
              modules="AspNetCoreModuleV2" 
              resourceType="Unspecified" />
          </handlers>
          <aspNetCore processPath="dotnet" 
            arguments=".\CookieSample.dll" stdoutLogEnabled="false" 
            stdoutLogFile=".\logs\stdout" hostingModel="inprocess" />
        </system.webServer>
      </location>
    </configuration>
    <!--ProjectGuid: 8F4EB672-B56E-4BC4-9909-A9EE199CDE1D-->
    

    You can set the maxAllowedContentLength in the web.config above without impacting the other sites than the above site.


1 additional answer

Sort by: Most helpful
  1. Bruce (SqlWork.com) 75,051 Reputation points
    2025-04-24T17:24:07.1666667+00:00

    you would update the IIS setting in the web.config of the site, so it only applies to the desired site.

    note: be sure the desired settings are not locked down in the IIS global configs.

    1 person found this answer helpful.
    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.