I'd like to have more than 1 setting for maxRequestLength - file size upload limitation (e.g. one for File/New, other for Picture/New). All of my Actions take additional parameters (e.g. /File/New?folderId=234).
Single setting works as expected:
<httpRuntime executionTimeout="60" maxRequestLength="1024" />
I tried to have 2 settings with 2 location sections in the root web.config, but without any success. I'm not sure what to write in "path" - physical aspx page of a view, or controller+action... however, nothing seems to work.
<location path="/File/">
<system.web>
<httpRuntime executionTimeout="60" maxRequestLength="4096" />
</system.web>
</location>
<location path="/Picture/">
<system.web>
<httpRuntime executionTimeout="60" maxRequestLength="1024" />
</system.web>
</location>
I tried to put another web.config in a specific view folder (e.g. /Views/Picture/...), like it works in classic Webform ASP.NET, but this doesn't seem to do the trick either...
<location path="">
<system.web>
<httpRuntime executionTimeout="60" maxRequestLength="1024" />
</system.web>
</location>
No matter what I do, only one value for httpRuntime.maxRequestLength is applied - that in (root) web.config...system.web.
The property, maxRequestLength indicates the maximum file upload size of 28.6MB, supported by ASP.NET. You cannot upload the files when the FileSize property is below the maxRequestLength value.
You have to increase the maxRequestLength setting in web.
The MaxRequestLength property specifies the limit for the buffering threshold of the input stream. For example, this limit can be used to prevent denial of service attacks that are caused by users who post large files to the server.
ASP.NET Core 2.0 enforces 30MB (~28.6 MiB) max request body size limit, be it Kestrel and HttpSys. Under normal circumstances, there is no need to increase the size of the HTTP request. But when you are trying to upload large files (> 30MB), there is a need to increase the default allowed limit.
I believe the Path attribute shouldn't start or end with a "/" - so you should have:
<location path="File">
<system.web>
<httpRuntime executionTimeout="60" maxRequestLength="4096" />
</system.web>
</location>
<location path="Picture">
<system.web>
<httpRuntime executionTimeout="60" maxRequestLength="1024" />
</system.web>
</location>
Your virtual or physical directory–level Web.config's shouldn't have the <location> elements.
That should sort you out.
The docs for the Location element even have this very example:
The following code example demonstrates how to set the uploaded file size limit to 128 KB for only the page specified.
<configuration>
<location path="UploadPage.aspx">
<system.web>
<httpRuntime maxRequestLength="128"/>
</system.web>
</location>
</configuration>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With