c# - .Net core api在保存大文件时返回404
问题描述
我有.net core api,它将文件保存在文件服务器上。当文件大小较小(例如 10 kb、1 Mb、10 Mb)时,它可以正常工作。但是,当我尝试保存 100 mb 的文件时,它返回:
404 - 找不到文件或目录。您要查找的资源可能已被删除、名称已更改或暂时不可用。
我更新了 kestrel 选项以忽略文件大小:
.UseKestrel(options => {
options.Limits.MaxRequestBodySize = null;
})
文件保存代码:
using (var imageFile = new FileStream(fullPath, FileMode.Create))
{
imageFile.Write(bytes, 0, bytes.Length);
imageFile.Flush();
}
网页配置:
<system.webServer>
<security>
<requestFiltering>
<requestLimits maxAllowedContentLength="4294967295" />
</requestFiltering>
</security>
但是,当托管在服务器上时,它仍然不起作用(对于大文件大小)。虽然当我使用 iis express 在本地机器上托管时它工作正常。
可能的原因是什么?或者我在这里缺少任何设置?
解决方案
请检查IIS 的 Unexpected Not Found 错误。您需要增加/设置maxAllowedContentLength
<system.webServer>
<security>
<requestFiltering>
<!-- This will handle requests up to 50MB -->
<requestLimits maxAllowedContentLength="52428800" />
</requestFiltering>
</security>
</system.webServer>
推荐阅读
- javascript - DataTable 列显示对象而不显示实际值?
- html - Google Maps Javascript 的可视化效果不佳
- javascript - 列出元素和 javascript 值
- python - Pygame,win.blit 不工作
- php - 除非目录名称以下划线开头,否则图像不会显示
- c - 蛮力算法导致未定义的行为
- swift - 如何将数据从一个视图控制器传递到另一个视图控制器以及在视图控制器之间有一个显示视图控制器
- dask - 读取/检索大型数据集时的 Dask 调度程序行为
- google-apps-script - 使用 Hubspot 跟踪 Google 幻灯片事件
- c# - 在第二个窗口中显示视频(UWP C#)