asp.net-web-api - 如何增加 .net core 中的请求限制?
问题描述
我正在尝试在我的 .net 核心 Web api 中上传一些大于 ~30Mb 限制的文件。我已经尝试遵循我找到的所有建议,所有建议都在下面列出。无论我尝试过什么,都会返回 404.13 错误“请求超出请求内容长度”。我在 Windows 10 上的 Visual Studio 中运行,有人知道我怎样才能让它工作吗?我猜在 IIS 上托管时情况可能会有所不同,但我试图首先在我的机器上运行它。
public static IWebHost BuildWebHost(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseKestrel(o => o.Limits.MaxRequestBodySize = null)
.UseStartup<Startup>()
.Build();
下面的这个在尝试获取 IHttpMaxRequestBodySizeFeature 时返回 null
appBuilder.ServerFeatures.Get<IHttpMaxRequestBodySizeFeature>.MaxRequestBodySize = null;
将其添加到我的 app.config 中:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<runtime>
<gcServer enabled="true"/>
</runtime>
<system.web>
<httpRuntime maxRequestLength="2147483647"/>
</system.web>
<system.webServer>
<security>
<requestFiltering>
<requestLimits maxAllowedContentLength="2147483647"/>
</requestFiltering>
</security>
</system.webServer>
</configuration>
向我的控制器添加属性:
[HttpPost]
[DisableRequestSizeLimit]
//[RequestSizeLimit(100_000_000)]
public IActionResult Document(IList<IFormFile> files)
解决方案
为了回答我自己的问题,事实证明我应该创建一个 Web.config 文件并将我放在 app.config 文件中的内容放入其中。
推荐阅读
- java - 在 android - java 中使用 mbtiles 文件或 sqlitedb 文件制作地图
- asp.net-mvc - 如何在 ADFS 2018 中配置注销后重定向 uri?
- flutter - Flutter web:svg上未处理的元素过滤器
- autodesk-forge - Autodesk-designautomation:内部服务器错误(错误代码 500):WorkItem 中缺少参数
- html - float 属性在块元素上的行为如何
- java - 如何在我的应用程序中使用 Explain 找到 Mysql 查询的缓慢性?
- python-3.x - 在使用唯一路径算法记忆我的结果时,我做错了什么吗?
- python - 如何在决策树分类器中解释标签编码的分类特征?
- c# - 在datagridview C#表单上的一行中仍然保留多个数据
- java - Stream 已被供应商操作或关闭