.Net Core POST 请求数组大小限制



我有一个用JavaScript编写的UI,带有.net核心后端。我在JS中的ajax调用看起来像这样:

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);
}
});

现在我遇到的问题是,当我的用户数组大于某个数字(不确定数字是多少(时,我的服务器似乎只是放弃了呼叫。例如,当我的用户数组大小为 15 时,我可以在 .NET 控制器中设置断点并很好地处理它。但是,当我的用户数组为 1000 时,我什至没有到达断点,我的服务器返回 500。是什么原因造成的,我该如何解决它?

我的控制器:

[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;
}

您需要在.net core api 应用程序的 web.config 中增加此值

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

最新更新