多部分正文长度限制超出异常 [英] Multipart body length limit exceeded exception

查看:18
本文介绍了多部分正文长度限制超出异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尽管在 web.config 部分中将 MaxRequestLengthmaxAllowedContentLength 设置为最大可能值,但 ASP.Net Core 不允许我上传大于 134,217,728 字节 的文件.来自网络服务器的确切错误是:

Although having set the MaxRequestLength and maxAllowedContentLength to the maximum possible values in the web.config section, ASP.Net Core does not allow me to upload files larger than 134,217,728 Bytes. The exact error coming from the web server is:

处理请求时发生未处理的异常.

An unhandled exception occurred while processing the request.

InvalidDataException:超过多部分正文长度限制 134217728.

InvalidDataException: Multipart body length limit 134217728 exceeded.

有没有办法解决这个问题?(ASP.Net 核心)

Is there any way to work this around? (ASP.Net Core)

推荐答案

看了 GitHub 上的一些帖子,我找到了解决这个问题的方法.结论是它们必须在 Startup 类中设置.例如:

I found the solution for this problem after reading some posts in GitHub. Conclusion is that they have to be set in the Startup class. For example:

public void ConfigureServices(IServiceCollection services)
{
        services.AddMvc();
        services.Configure<FormOptions>(x => {
            x.ValueLengthLimit = int.MaxValue;
            x.MultipartBodyLengthLimit = int.MaxValue; // In case of multipart
        })
 }

这将解决问题.但是他们也表示有一个 [RequestFormSizeLimit] 属性,但我还无法引用它.

This will solve the problem. However they also indicated that there is a [RequestFormSizeLimit] attribute, but I have been unable to reference it yet.

这篇关于多部分正文长度限制超出异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆