c# - 带有 JSON 数据的大型 POST 请求在 ASP.NET Core 4.6.1 中未反序列化
问题描述
我有一个网络 API:
[Route("api/MyResource")]
public IHttpActionResult Post([FromBody] MyDTO myResource, int resourceId)
其中 MyDTO 包含很多其他 DTO 数组。
当我发送较小的请求时,一切正常,但是在 MyDTO 的数组中有数千个对象(cca 5 MB)时,myResource 为空。
我也尝试将 myResource 参数的类型更改为object
,但得到了相同的结果。较小的请求被反序列化为JObject
,大的被反序列化为 null。我在输出窗口或错误 http 响应中没有异常。
我正在 IIS-Express 中调试应用程序。
为什么我得到 null 以及如何解决它?
解决方案
您可以更新maxAllowedContentLength
web.config 中的
<security>
<requestFiltering>
<requestLimits maxAllowedContentLength="52428800" />
</requestFiltering>
</security>
如果不成功也设置
<system.web>
<httpRuntime maxRequestLength="65536" />
</system.web>
推荐阅读
- javascript - 根据角色和权限隐藏/显示组件中的菜单和元素
- node.js - 将 Node JS 应用程序部署到 Google 云 500 服务器错误
- php - #Wordpress 如何在函数内运行联系表格 7 过滤器
- python - PostgreSQL:无法加载库 llvmjit.so
- asp.net-core - 如何从 ASP.NET CORE ActionFilter 中的 ActionExecutingContext 对象访问 ModelState 和 ValueProvider 对象
- html - 如果您的复选框被单击,如何制作一个 if..else 语句将返回 true?
- postgresql - PostgreSQL 将 .sql 文件转换为 .csv 文件
- python-3.x - StaleElementReferenceException:陈旧的元素参考:元素未附加到页面文档python
- plot - 使用 gnuplot 绘制拟合函数中的错误
- npm - 不小心增加了 package-lock.json lockfileVersion。如何还原?