简体   繁体   中英

.Net Core POST Request Array size limit

I have a UI written in JavaScript with a .net core backend. My ajax call in JS looks like this:

const data = { users: userArray, message: sendMessage, url: optUrl };

$.ajax({
    type: "POST",
    url: `${App_Url}/ui/Notifications/send`,
    dataType: "application/json",
    data: JSON.stringify(data),
    success: (response) => {
        // if (spinner)
        //   spinner.stop();
        //
        notifySuccess("Users imported successfully!");
        $("#user_table").html(response);
    },
    error: (error) => {
        //if (spinner)
        //  spinner.stop();
        //
        notifyErrors(error.responseJSON.errors);
    }
});

Now the problem that I'm having is that when my userArray is bigger than some number (not sure what the number is) then my server seems to just drop the call. For example when my userArray is size 15 I can set a break point in the .NET controller and get to it just fine. However when my userArray is 1000 I don't even get to the break point and my server returns a 500. What is causing this and how do I go about fixing it?

My controller:

    [HttpPost("send")]
    [DisableRequestSizeLimit]
    public async Task<IActionResult> SendNotificationsAsync(CustomNotificationRq request)
    {
        var token = await _service.GetMiddlewareToken();
        var users = request.users;
        var message = request.message;
        var url = request.url;

        var response = await _service.SendNotificationAsync(users.ToList(), message, url, token.token);


        return response;
    }

You need to increase this value in your web.config in your .net core api application

<appSettings>
  <add key="aspnet:MaxJsonDeserializerMembers" value="150000" />
</appSettings>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM