0

I've a C# ASP.NET Core MVC website. I'm running it in Visual Studio. I'm posting to a controller action that takes parameter string[] identifiers. The HTML form element is a textarea that has values like:

one
two
three

This works fine, and identifiers is properly populated with 3 entries.

If the textarea instead has 37,000+ lines (1.4 MB when saved to disk as a text file), then the controller sees identifiers as NULL.

In my Startup.cs I've used (and have also used with just the defaults):

services.Configure<IISServerOptions>(o =>
{
    o.MaxRequestBodySize = int.MaxValue;
});

services.Configure<KestrelServerOptions>(o =>
{
    o.Limits.MaxRequestBodySize = int.MaxValue;
});

services.Configure<FormOptions>(o =>
{
    o.ValueLengthLimit = int.MaxValue;
    o.MultipartBodyLengthLimit = int.MaxValue;
});

And my web.config (I'm running this from Visual Studio, and web.config is set to "Copy Always") contains:

<configuration>
  <system.webServer>
    <security>
      <requestFiltering>
        <requestLimits maxAllowedContentLength="1073741824" />
      </requestFiltering>
    </security>
</configuration>

There are no errors or warnings in the Windows Event Viewer, so I suspect it's an issue in code?

Assuming the issue is related to max POST size, where have I gone wrong?

Update The data is posted with jQuery ajax, with no contentType specified. I think the default is: 'application/x-www-form-urlencoded; charset=UTF-8' which likely limits the request to 2k. Though explicitly setting a contentType doesn't seem to help.

Developer Webs
  • 983
  • 9
  • 29
  • Does this answer your question? [Can HTTP POST be limitless?](https://stackoverflow.com/questions/2880722/can-http-post-be-limitless) – devlin carnate Aug 22 '23 at 16:14
  • The answers in that thread should give you some ideas on things to check. Since we don't have access to your environment, it's up to you to research and figure out what is imposing the limitation. – devlin carnate Aug 22 '23 at 16:15
  • @devlincarnate FormOptions.ValueLengthLimit defaults to nearly 30 MB, but that should be far more than I need anyway. – Developer Webs Aug 22 '23 at 16:17
  • What is the Response code? Check dev tools in your browser (F12). – mxmissile Aug 22 '23 at 17:53
  • @mxmissile The response code will be an exception because the controller's parameter is receiving a list as NULL instead of having values. The controller attempts to iterate through the list (which is a NULL object) – Developer Webs Aug 22 '23 at 18:49
  • Inspect the Request object in your action method with your debugger. Might have some hints. – mxmissile Aug 22 '23 at 19:54
  • @mxmissile When I have the 37,000+ rows in the textarea Chrome's "Payload" tab shows nothing at all. But when there are about ~10,000 records it properly shows an array with the expected number of elements. – Developer Webs Aug 22 '23 at 20:03
  • Try changing your ` – mxmissile Aug 22 '23 at 20:25
  • @mxmissile I didn't know textarea had a maxlength. My value is 1.3 million characters. I set the maxlength to 2000000 (2 million), but alas the same bug persists. A few thousand records works, not sure what is happening. I might have to install Wireshark or similar to see what is actually being posted I suppose. – Developer Webs Aug 22 '23 at 20:44
  • 1
    I was afraid of that, the fact that Chrome's Payload shows nothing AND you are not actually getting a payload leads me to believe this is a browser or jquery issue. – mxmissile Aug 22 '23 at 20:49
  • @mxmissile I was thinking the same. I've WireShark installed now, I'll soon know if the value is being posted or not. At least that'll narrow down where the issue is. It's being posted with jQuery's ajax, I'm thinking it might be the issue. – Developer Webs Aug 22 '23 at 21:21
  • Could you share your html code and posted with jQuery ajax code ?So that we can reproduce your problem. If you added [minimal reproducible example](https://stackoverflow.com/help/minimal-reproducible-example), it would be easier to tell. I'm not sure, at this stage. – Qing Guo Aug 23 '23 at 01:53

1 Answers1

0

To fix the issue I had to add the following to my controller:

[RequestFormLimits(ValueCountLimit = int.MaxValue)]

I had thought the code below would do the same thing, but it does not solve the problem. Note that services is an instance of IServiceCollection and is used in my Startup.cs (where we also inject our settings, database connection, set session details, etc).

services.Configure<FormOptions>(options =>
{
    options.ValueCountLimit = int.MaxValue;
    options.ValueLengthLimit = int.MaxValue;
});
Developer Webs
  • 983
  • 9
  • 29