【问题标题】:404 Error - Uploading file size greater than 30 MB404 错误 - 上传的文件大小超过 30 MB
【发布时间】:2019-05-11 03:31:51
【问题描述】:

在我们的 Web API 中,我们不能上传超过 30MB 的 fize 大小。我们曾经收到 404 错误,例如“404 - 找不到文件或目录。 您要查找的资源可能已被删除、名称已更改或暂时不可用。"

通过谷歌搜索和查看各种帖子,我厌倦了配置文件中的以下更改:

Web.Config:

<system.web>
     <httpRuntime maxRequestLength="204800" timeout="7200" />
</system.web>
<requestFiltering>
     <requestLimits maxAllowedContentLength="209715200" maxQueryString="2097151" maxUrl="10999"/>
</requestFiltering>

但是,我仍然无法上传大小超过 30MB 的文件。但是相同的代码可以正常上传小于 30 MB 的文件。

我在这里错过了什么?

【问题讨论】:

  • 实际上太大时找不到资源?对我来说似乎很奇怪。 413(请求实体太大)不是更合适吗?

标签: c# asp.net-web-api file-upload filesize upload-max-filesize


【解决方案1】:

1.) 打开 IIS 管理器。

2.) 选择您要配置的网站。

3.) 确保您位于管理器底部按钮的“功能视图”中。

4.) 选择请求过滤并通过双击图标将其打开。将显示“请求筛选”窗格。

5.) 在屏幕右侧的“操作”窗格中,单击“编辑功能设置...”链接。将显示“编辑请求过滤设置”窗口。

6.) 在请求限制部分,输入适当的最大允许内容长度(字节),然后单击确定按钮。 重启 IIS。

这对我有用:)

【讨论】:

  • 是 404.13 吗?尝试重启服务器。
  • 您 100% 确定您配置了正确的网站。昨天我尝试时,这立即奏效了。
【解决方案2】:

您能否更改您的 web.config 以使用 system.webServersecurity

<configuration>
    <system.web>
        <httpRuntime maxRequestLength="204800" />
    </system.web>
    <system.webServer>
        <security>
            <requestFiltering>
                <requestLimits maxAllowedContentLength="209715200" />
            </requestFiltering>
        </security>
    </system.webServer>
</configuration>

【讨论】:

    【解决方案3】:

    加入对我有用的东西。 我必须做出两个改变:

    使用以下设置更新web.config

    <system.webServer>
                <security>
                    <requestFiltering>
                        <requestLimits maxAllowedContentLength="209715200" />
                    </requestFiltering>
                </security>
            </system.webServer>
    

    但是仅使用它对我不起作用。我必须向 API Controller 添加另一个属性才能使其工作。

    [HttpPost]
    //[DisableRequestSizeLimit]
    [RequestSizeLimit(70_000_000)] //Files sizes upto 70 MB are allowed
    

    我的设置是带有 ASP Hosted 选项的 Blazor WebAssembly 模板。希望这对某人有所帮助。

    【讨论】:

    猜你喜欢
    • 2011-11-01
    • 2013-12-11
    • 2020-01-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-06-03
    相关资源
    最近更新 更多