Asp.net Core 2.0 RequestSizeLimit attribute not working

后端 未结 2 608
天命终不由人
天命终不由人 2020-12-06 10:25

I\'m creating a website in Asp.net core 2.0 which allows files to be uploaded. I quickly came across the problem of the 30MB upload limit and receive a 4

相关标签:
2条回答
  • 2020-12-06 10:35

    For anyone else with the same problem, this is the answer.

    Mark LaFleur's answer was the right direction but the web.config was missing a crucial section.

    I was helped but this webpage that explains more about the web.config file in Asp.net Core: ASP.NET Core Module configuration reference

    To stop this error you need to create a web.config file with the following content:

    <?xml version="1.0" encoding="utf-8"?>
    <configuration>
      <system.webServer>
        <handlers>
          <add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified" />
        </handlers>
        <security>
          <requestFiltering>
            <!-- This will handle requests up to 50MB -->
            <requestLimits maxAllowedContentLength="52428800" />
          </requestFiltering>
        </security>
      </system.webServer>
    </configuration>
    
    0 讨论(0)
  • 2020-12-06 10:42

    The RequestSizeLimit attribute allows you to define the maximum request size within your code but it is still limited by maximum request size supported by the server itself.

    In this case, I suspect you're receiving this error:

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

    This error is being triggered by ISS because the call exceeded IIS' maxAllowedContentLength value (the default is 30,000,000). From the documentation:

    The following error indicates your file upload exceeds the server's configured maxAllowedContentLength. The default setting is 30000000, which is approximately 28.6MB. The value can be customized by editing the web.config:

    <system.webServer>
      <security>
        <requestFiltering>
          <!-- This will handle requests up to 50MB -->
          <requestLimits maxAllowedContentLength="52428800" />
        </requestFiltering>
      </security>
    </system.webServer>
    
    0 讨论(0)
提交回复
热议问题