超出多部分正文长度限制异常

超出多部分正文长度限制异常

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

问题描述

尽管已将 MaxRequestLengthmaxAllowedContentLength 设置为 web.config 部分中的最大可能值,但 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:

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

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.

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

08-04 22:34