HTTP Error 404.13 - asp.net core 2.0

后端 未结 3 1356
日久生厌
日久生厌 2020-12-10 05:11

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

Verify the

相关标签:
3条回答
  • 2020-12-10 05:23

    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>
    
    0 讨论(0)
  • 2020-12-10 05:25

    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 讨论(0)
  • 2020-12-10 05:30

    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 讨论(0)
提交回复
热议问题