gpt4 book ai didi

Can't change the maximum request size (http error 413)(无法更改最大请求大小(http错误413))

转载 作者:bug小助手 更新时间:2023-10-22 14:29:47 30 4
gpt4 key购买 nike



.net core 7 in development mode with vs 22, trying to get file of 50mb but getting http error 413.

.net core 7在开发模式下使用vs22,试图获得50mb的文件,但得到http错误413。


I've tried a lot of different configuration but nothing seem to work.

我尝试了很多不同的配置,但似乎都不起作用。


examples:

示例:


setting.json:

setting.json:


"HttpRuntime": {
"RequestSizeLimit": 524288000
}
"maxAllowedContentLength": 524288000

program.cs:

程序.cs:


builder.WebHost.ConfigureKestrel(opt => opt.Limits.MaxRequestBodySize = long.MaxValue);
builder.Services.Configure<IISServerOptions>(options => {
options.MaxRequestBodySize = int.MaxValue;
});
builder.Services.Configure<Microsoft.AspNetCore.Http.Features.FormOptions>(options => {
options.MultipartBodyLengthLimit = 50 * 1024 * 1024;
});
builder.Services.Configure<KestrelServerOptions>(options => {
options.Limits.MaxRequestBodySize = null;
});

But nothing seem to work.

但似乎什么都不起作用。


Your help will be appreciated.

我们将感谢您的帮助。


更多回答
优秀答案推荐

Above POST method you can have RequestFormLimits attribute. This attribute is needed for setting the maximum allowed file size.
Finally, on the Web.Config file set the maxAllowedContentLength as shown below.

在POST方法之上,您可以具有RequestFormLimits属性。此属性是设置允许的最大文件大小所必需的。最后,在Web.Config文件上设置maxAllowedContentLength,如下所示。


<requestLimits maxAllowedContentLength="104857600" />

Please read the following article for more knowledge. Set MaxRequestLength in ASP.Net Core

请阅读以下文章了解更多信息。在ASP.Net核心中设置MaxRequestLength


if this is not successful could you please add the following in the startup file or program.cs file? in the ConfigureServices method?

如果不成功,你能在启动文件或program.cs文件中添加以下内容吗?在ConfigureServices方法中?


services.Configure<FormOptions>(x =>
{
x.ValueLengthLimit = int.MaxValue;
x.MultipartBodyLengthLimit = int.MaxValue;
x.MultipartHeadersLengthLimit = int.MaxValue;
});


We need to add web.config file with maxAllowedContentLength setting in asp.net core project. It can fix the issue.

我们需要在asp.net核心项目中添加具有maxAllowedContentLength设置的web.config文件。它可以解决这个问题。


I have test it in my local and it works well.

我在本地测试过,效果很好。


project structure

项目结构


Both configurations of application level and machine level(add the web.config file manually) are necessary.

应用程序级别和计算机级别的配置(手动添加web.config文件)都是必需的。


//
The size limit is configured within the file program.cs, you need to add the following settings:

//大小限制是在文件程序中配置的。.cs,您需要添加以下设置:


builder.Services.Configure<FormOptions>(options =>
{
options.ValueLengthLimit = int.MaxValue;
options.MultipartBodyLengthLimit = int.MaxValue;
options.MultipartHeadersLengthLimit = int.MaxValue;
});

Please add the file web.config right under your root directory of your project, and add the following settings:

请在项目的根目录下添加web.config文件,并添加以下设置:


<configuration>
<system.webServer>
<security>
<requestFiltering>
<!-- 1 GB -->
<requestLimits maxAllowedContentLength="1073741824" />
</requestFiltering>
</security>
</system.webServer>
</configuration>

If it is deployed on IIS,the Web.config is auto-generated,please also add the settings above.

如果它部署在IIS上,则Web.config是自动生成的,还请添加上面的设置。


更多回答

So in .net core 7 there is no web.config, u need to add it manually with the <requestLimits maxAllowedContentLength="104857600" /> and then it's work. There is no need for: using System.IO; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Hosting; and no need for The RequestFormLimits attribute - doen't seem to do anything. Maybe it's add another limit ontop of the web config - i didn't test 4 it. Thx

因此,在.net core 7中没有web.config,您需要使用手动添加它,然后它就可以工作了。不需要:使用System.IO;使用Microsoft.AspNetCore.Mvc;使用Microsoft.AspNetCore.Http;使用Microsoft.AspNetCore.Hosting;并且不需要RequestFormLimits属性-似乎什么都没做。也许这是在网络配置的顶部添加了另一个限制-我没有测试它

@mudale - I updated my answer. could you please try that one too?

@穆代尔-我更新了我的答案。你也可以试试那个吗?

i've tested the: services.Configure<FormOptions>(x => { x.ValueLengthLimit = int.MaxValue; x.MultipartBodyLengthLimit = int.MaxValue; x.MultipartHeadersLengthLimit = int.MaxValue; }); And it's not working without setting of the requestLimits in the web.config...

我已经测试了:服务。配置(x=>{x.ValueLengthLimit=int.MaxValue;x.MultipartBodyLengthLimit=int.MaxValue;x.MultippartHeadersLengthLimit=int.Maxalue;});如果不在web.config中设置requestLimits,它就无法工作。。。

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com