带有JSON数据的大型POST请求未在ASP.NET Core 4.6.1中反序列化

问题描述 投票:0回答:1

我有一个web api:

[Route("api/MyResource")]
public IHttpActionResult Post([FromBody] MyDTO myResource, int resourceId)

其中MyDTO包含很多其他DTO。

当我发送较小的请求时,一切正常,但是在MyDTO的数组中有数千个对象(cca 5 MB),myResource为null。

我也尝试将myResource参数的类型更改为object,但我得到了相同的结果。较小的请求被反序列化为JObject,大到null。我在输出窗口或错误http响应中没有异常。

我正在IIS-Express中调试应用程序。

为什么我得到null以及如何修复它?

c# iis asp.net-web-api json.net .net-4.6.1
1个回答
1
投票

您可以在web.config中更新maxAllowedContentLength

<security>
  <requestFiltering>
    <requestLimits maxAllowedContentLength="52428800" />
  </requestFiltering>
</security>

如果没有成功也设定

<system.web>
  <httpRuntime maxRequestLength="65536" />
</system.web>
© www.soinside.com 2019 - 2024. All rights reserved.