c# – HTTP错误404.13 – asp.net core 2.0

HTTP Error 404.13 – Not Found The request filtering module is
configured to deny a request that exceeds the request content length.

Verify the
configuration/system.webServer/security/requestfiltering/requestLimits@maxAllowedContentLength
setting in the applicationhost.config or web.config file.

我不知道我在哪里可以配置,在asp.net核心2中有改变使用appsettings.json而不是.

甚至尝试这样做,但它不起作用.

services.Configure<FormOptions>(options =>
{
    options.MultipartBodyLengthLimit = 300_000_000;
});

解决方法

如果您使用IIS,则需要在asp.net core 2.0 app中添加web.config.

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <system.webServer>
    <security>
      <requestfiltering>
        <!-- This will handle requests up to 700MB (CD700) -->
        <requestLimits maxAllowedContentLength="737280000" />
      </requestfiltering>
    </security>
  </system.webServer>
</configuration>

如果您不使用IIS,则可以在控制器中使用[RequestSizeLimit(long.MaxValue)]或[disableRequestSizeLimit]属性.

此外,您可以在Program.cs中添加全局设置:

.UseKestrel(o => { o.Limits.MaxRequestBodySize = null; })

有关详细信息,请参阅此https://github.com/aspnet/Announcements/issues/267

相关文章

本文将从上往下,循序渐进的介绍一系列相关.NET的概念,先从...
基于 .NET 的一个全新的、好用的 PHP SDK + Runtime: Pe...
.NET 异步工作原理介绍。
引子 .NET 6 开始初步引入 PGO。PGO 即 Profile Guided Opti...
前言 2021/4/8 .NET 6 Preview 3 发布,这个版本的改进大多来...
前言 开头防杠:.NET 的基础库、语言、运行时团队从来都是相...