How to increase the maximum file upload size in ASP.NET CORE?
Question:
In ASP.NET core MVC 6, how to upload the maximum file to unlimited? Solution:
ASP.NET CORE 2.0 and higher versions add additional file size limit through the Kestrel server, which is separated from IIS limit. To increase file upload size, you can use one of the following methods:
For a specific MVC operation or controller, you can use
attributes to set the maximum request text size limit. For example, set themethod of the controller to 100,000,000 bytes:
RequestSizeLimit
MyController
For the request that the unrepaired MVC operation, according to the basic configuration limit of each request, please use MyAction
:
<code class="language-csharp">[HttpPost] [RequestSizeLimit(100_000_000)] public IActionResult MyAction([FromBody] MyViewModel data) { //... }</code>
Global configuration:
To change the maximum request the size of the maximum request, please modify the attribute in the IHttpMaxRequestBodySizeFeature
or
<code class="language-csharp">app.Run(async context => { context.Features.Get<IHttpMaxRequestBodySizeFeature>().MaxRequestBodySize = 100_000_000; });</code>
Set
Startup.Configure
or in the HTTPSYS configuration in the Kestrel configuration to 0 to the request text size limit. UseKestrel
The above is the detailed content of How to Increase Maximum File Upload Size in ASP.NET Core?. For more information, please follow other related articles on the PHP Chinese website!