Reputation: 101
How can I set maximum upload size for an ASP.NET Core MVC application?
In the past I was able to set it in web.config
file like this:
<system.webServer>
<security>
<requestFiltering>
<requestLimits maxAllowedContentLength="52428800" />
</requestFiltering>
</security>
</system.webServer>
Upvotes: 10
Views: 8623
Reputation: 6390
Two ways to do that:
1.Using application wise settings - in the > configure services method.
services.Configure<FormOptions>(options =>
{
options.MultipartBodyLengthLimit = 52428800;
});
2.Using RequestFormSizeLimit attribute - for specific actions. - It is not yet available in official package Unofficial
Upvotes: 5
Reputation: 10889
You can configure the max limit for multipart uploads in the ConfigureServices
method:
public void ConfigureServices(IServiceCollection services)
{
services.Configure<FormOptions>(options =>
{
options.MultipartBodyLengthLimit = 52428800;
});
services.AddMvc();
}
You can also configure the MaxRequestBufferSize
by using services.Configure<KestrelServerOptions>
, but it looks like this is going to be deprecated in the next release.
Upvotes: 2