Elevate ASP.NET Core file upload size limit
]In ASP.NET Core, you may encounter file upload size limits. To resolve this issue, you need to consider the restrictions imposed by both the Web Server (IIS) and the ASP.NET Core Server (Kestrel).
IIS file size limit
]As mentioned in the link resource you provide, IIS has default limits on file upload size. To increase this limit for your application, follow these steps:
Kestrel file size limit
]Since ASP.NET Core 2.0, Kestrel has also imposed its own restrictions on file uploads. These limitations are defined in the KestrelServerLimits.cs file.
To increase the file size limit in Kestrel, you can use the following methods:
MVC operation method
]Use the [RequestSizeLimit]
feature on a specific MVC operation method or controller to override the default limit. For example:
[HttpPost]
[RequestSizeLimit(100_000_000)]
public IActionResult MyAction([FromBody] MyViewModel data)
{
}
General Middleware
]Use the IHttpMaxRequestBodySizeFeature
feature to modify the limit for each request:
app.Run(async context =>
{
context.Features.Get().MaxRequestBodySize = 100_000_000;
});
Global configuration
]Modify the MaxRequestBodySize
property in the callback function of UseKestrel
or UseHttpSys
to set the limit globally:
.UseKestrel(options =>
{
options.Limits.MaxRequestBodySize = null; // 无限制
});
.UseHttpSys(options =>
{
options.MaxRequestBodySize = 100_000_000;
});
Through the above steps, you can increase the file upload size limit for both the web server and the Kestrel server in ASP.NET Core.
Disclaimer: All resources provided are partly from the Internet. If there is any infringement of your copyright or other rights and interests, please explain the detailed reasons and provide proof of copyright or rights and interests and then send it to the email: [email protected] We will handle it for you as soon as possible.
Copyright© 2022 湘ICP备2022001581号-3