我有一个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以及如何修复它?
您可以在web.config中更新maxAllowedContentLength
<security>
<requestFiltering>
<requestLimits maxAllowedContentLength="52428800" />
</requestFiltering>
</security>
如果没有成功也设定
<system.web>
<httpRuntime maxRequestLength="65536" />
</system.web>