Submitting large number of form-values in ASP.NET Core 1.0

 September 21, 2016


Backstory

Prior to submitting my entry in this year's 10k apart competition, I played-around with the overall board-size to see how well browsers could handle tens of thousands of DOM-elements. The result: not too well. There are just too many styling rules within the grid and performance noticably suffers. For example, a 32x32 grid contains a minimum of 6,144 child-elements (six-elements per "pixel"). The grid is wrapped with a form-tag and when submitted, results in 1,024 values being submitted…

I have also setup a permanent site for my entry post-competition: https://www.fav.rocks/.

ASP.NET protects you from large form submissions

In my case, I received a runtime exception: InvalidDataException: Form value count limit 1024 exceeded. No fear, though, since this is completely customizable with FormOptions. Just configure this class and you can set the form-value count to whatever you need:

Startup.cs

using Microsoft.AspNetCore.Http.Features;

public void ConfigureServices(IServiceCollection services)
{
    services.Configure<FormOptions>(x => x.ValueCountLimit = 2048);
    services.AddMvc();
}

In pre-Core days, you could use RequestFormSizeLimit and decorate your controller-action. I cannot seem to find an equivalent in Core, so if anyone knows something, leave a comment.