10

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>
2
  • Are you hosting on IIS? If yes, did you try to put this into your web.config to see if it works? Commented Oct 26, 2016 at 15:44
  • 1
    What kind of upload is it? There's only a built in limit for Forms and multipart. github.com/aspnet/Performance/blob/… Commented Oct 26, 2016 at 17:03

2 Answers 2

5

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

Sign up to request clarification or add additional context in comments.

Comments

2

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.