Home > Backend Development > C++ > How to Increase File Upload Size Limits in ASP.NET Core?

How to Increase File Upload Size Limits in ASP.NET Core?

Barbara Streisand
Release: 2025-01-29 01:26:09
Original
981 people have browsed it

How to Increase File Upload Size Limits in ASP.NET Core?

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.

    Navigation to the application pool used by your website.
  1. Right -click and select "Properties".
  2. On the "limit" tab, add the value of "maximum allowable content length".
  3. Kestrel file size limit

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:

MVC operation method

Use

features on a specific MVC operation method or controller to cover the default limit. For example:

General middleware

[RequestSizeLimit]

Use Features to modify the limit of each request:
<code class="language-csharp">[HttpPost]
[RequestSizeLimit(100_000_000)]
public IActionResult MyAction([FromBody] MyViewModel data)
{
}</code>
Copy after login

Global configuration

In the or IHttpMaxRequestBodySizeFeature callback function, modify the

attribute to set the global settings limit:
<code class="language-csharp">app.Run(async context =>
{
    context.Features.Get<IHttpMaxRequestBodySizeFeature>().MaxRequestBodySize = 100_000_000;
});</code>
Copy after login

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!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template