Improve the size limit of the ASP.NET core file upload
In ASP.NET CORE, you may encounter a file upload limit. To solve this problem, you need to consider restrictions on the web server (IIS) and ASP.NET Core servers (Kestrel).
IIS file size limit
As mentioned in the link resources you provided, IIS has the default limit on the size of the file upload. To increase this limit of the application, follow the following steps:
Open the IIS manager.
From ASP.NET CORE 2.0, Kestrel also applied its own restrictions on the file upload. These are limited in KestrelServerLimits.cs files. To add the file size limit in Kestrel, you can use the following methods:
Use
features on a specific MVC operation method or controller to cover the default limit. For example:
General middleware [RequestSizeLimit]
<code class="language-csharp">[HttpPost] [RequestSizeLimit(100_000_000)] public IActionResult MyAction([FromBody] MyViewModel data) { }</code>
Global configuration
In the or IHttpMaxRequestBodySizeFeature
callback function, modify the
<code class="language-csharp">app.Run(async context => { context.Features.Get<IHttpMaxRequestBodySizeFeature>().MaxRequestBodySize = 100_000_000; });</code>
Through the above steps, you can at the same time add the files of the web server and the Kestrel server in ASP.NET CORE to upload the size limit.
The above is the detailed content of How to Increase File Upload Size Limits in ASP.NET Core?. For more information, please follow other related articles on the PHP Chinese website!