Search code examples
htmlasp.net-mvcformsasp.net-coretinymce

ASP NET - tinyMCE editor - Error 400 bad request


I am develeping web application where is in one form used tinyMCE editor. Users of the application uses this tinyMCE input field for saving screenshots and notes. That is fact and it cannot be easily undone.

Problem is that when someone pastes to big screeshot or too many or something, application doesn't save it on submit but error 400 bad request is given. Also when i add some extra input into another input field, it works. It means it must be somehow limitation of one single input field.

I tried to come to to top limit where it still works and it is something close to 4 000 000 characters - which might be much more bytes.

I already tried to search soem limits of html input field and tinyMCE limits but found nothing helpful.

I also tried to increase form limit in startup of ASPNET app:

services.Configure<FormOptions>(options =>
{
   //Set the limit 
   options.MultipartBodyLengthLimit = limit;  
});

Does anybody know what might be causing it?

EDIT: I laready tried following app configuration:

builder.Services.Configure<FormOptions>(options =>
{
   // Set the limit to 128 MB
   options.MultipartBodyLengthLimit = 134217728;
});

builder.Services.Configure<IISServerOptions>(options =>
{
   // Set the limit to 128 MB
   options.MaxRequestBodySize = 134217728;
});

builder.WebHost.ConfigureKestrel(serverOptions =>
{
   // Set the limit to 128 MB
   serverOptions.Limits.MaxRequestBodySize = 134217728;
});

builder.Services.Configure<KestrelServerOptions>(options => 
{
   //  Set the limit to 128 MB
   options.Limits.MaxRequestBodySize = 134217728;
});

Solution

  • SOLUTION

    I did not give up googling and find that I can setup size of individual form value:

    builder.Services.Configure<FormOptions>(options =>
    {
       // Set the limit to 128 MB
       options.MultipartBodyLengthLimit = 134217728;
       options.ValueLengthLimit = 134217728;
    });
    

    The second line of the options settings solves the problem.

    I found the solution on stack overflow as well and I am surprised i did not see it first time I was trying to find the answer.

    see: stackoverflow solution