11
votes

HTTP Error 404.13 - Not Found The request filtering module is configured to deny a request that exceeds the request content length.

Verify the configuration/system.webServer/security/requestFiltering/requestLimits@maxAllowedContentLength setting in the applicationhost.config or web.config file.

I've no idea to where can i config that, in asp.net core 2 there has change to use appsettings.json instead.

Even try to do this already, but it's not work.

services.Configure<FormOptions>(options =>
{
    options.MultipartBodyLengthLimit = 300_000_000;
});
3
Asp.net core can have a web.config file, if you host it in IIS. Also read : docs.microsoft.com/en-us/aspnet/core/fundamentals/… .Styxxy

3 Answers

37
votes

If you use IIS, you need add web.config in your asp.net core 2.0 app.

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <system.webServer>
    <security>
      <requestFiltering>
        <!-- This will handle requests up to 700MB (CD700) -->
        <requestLimits maxAllowedContentLength="737280000" />
      </requestFiltering>
    </security>
  </system.webServer>
</configuration>

If you are not using IIS you can use [RequestSizeLimit(long.MaxValue)] or [DisableRequestSizeLimit] attribute in your controller.

Also, you can add a global setting in Program.cs:

.UseKestrel(o => { o.Limits.MaxRequestBodySize = null; })

For more info see this https://github.com/aspnet/Announcements/issues/267

0
votes

For my Core 2.2 MVC project, combining the [RequestSizeLimit(long.MaxValue)] attribute and the web.config above did not work. The web.config alone worked - Just don't use the attribute. The application crashed and closed the browser unexpectedly. Also, because my max request size is 200Mb, if it's possible to generate a 404.13 (req. too large) result, then your normal status code handling will not work for the 404.13 (see Startup.cs, Configure(), the

app.UseStatusCodePagesWithReExecute("/Error/Error", "?statusCode={0}");

line). The status code pages handling works for other codes though. I had to insert custom error status handling into the web.config file to handle 404.13 with a graceful user friendly view. Note that the 'remove' for the 404.13 also appears to remove status code 404 ... and then your Error controller method will not handle a 404. There are two custom error handlers in the web.config below - One for the 404.13 and one for the 404 in order to fix this. Hope this helps someone:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <system.webServer>
    <security>
      <requestFiltering>
        <!-- This will handle requests up to 201Mb -->
        <requestLimits maxAllowedContentLength="210763776" />
      </requestFiltering>
    </security>
    <httpErrors errorMode="Custom" existingResponse="Replace">
      <remove statusCode="404" subStatusCode="13" />
      <remove statusCode="404" />
      <error statusCode="404"
             subStatusCode="13"
             prefixLanguageFilePath=""
             path="/Error/UploadTooLarge"
             responseMode="Redirect" />
      <error statusCode="404"
             prefixLanguageFilePath=""
             path="/Error/PageNotFound"
             responseMode="Redirect" />
    </httpErrors>
  </system.webServer>
</configuration>

The end result is that all normal status codes are handled by Error/Error, and the 404.13 and 404 status codes have custom handling ... and nice views all around!

0
votes

The default value of 30000000 Bytes for the content length, which was not sufficient for me in some of the file uploading functionalities.

<system.webServer>
    <security>

      <requestFiltering>
        <requestLimits maxAllowedContentLength="500000000"></requestLimits>

      </requestFiltering>
    </security>

  </system.webServer>