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
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>
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 is30000000, which is approximately28.6MB. The value can be customized by editing theweb.config:<system.webServer> <security> <requestFiltering> <!-- This will handle requests up to 50MB --> <requestLimits maxAllowedContentLength="52428800" /> </requestFiltering> </security> </system.webServer>