MaxRequestBodySize 无法在具有 Azure 应用服务的 Web 服务器中工作

Hem*_*a S 5 .net-core asp.net-core-3.1

当使用 Azure 应用服务部署到 Web 服务器时,MaxRequestBodySize 不起作用,但它在我的本地工作。我尝试对 .net core 3.1 的program.cs 和startup.cs 进行以下更改,但没有一个起作用。仍然收到 413(请求实体太大)错误。

Program.cs:
1. webBuilder.ConfigureKestrel(serverOptions =>
                       {
                           serverOptions.Limits.MaxRequestBodySize = long.MaxValue;
                       })


2. .UseKestrel(options =>
{
    options.Limits.MaxRequestBodySize = long.MaxValue;
}

Startup.cs
services.Configure<IISServerOptions>(options => options.MaxRequestBodySize = long.MaxValue);
Run Code Online (Sandbox Code Playgroud)

小智 10

转到 Web 应用的 kudu 控制台 (https://{your-website-name}.scm.azurewebsites.net/)。单击菜单中的“调试控制台”下拉菜单并选择“CMD”。您将看到下面列出的 Web 应用程序目录结构。使用列表界面导航至站点 > wwwroot。向下滚动到底部,直到看到web.config文件。单击文件左侧的编辑图标,这将在编辑器中打开该文件。在 <system.webServer> 下添加以下行:

   <security>
      <requestFiltering>
        <requestLimits maxAllowedContentLength="4294967295"  />
      </requestFiltering>
    </security>  
Run Code Online (Sandbox Code Playgroud)

这会将最大请求长度设置为 4 GB。关闭 kudu 控制台并从 azure 门户重新启动应用程序。然后再试一次。

  • 谢谢,这对我很有帮助。有没有办法在发布过程中编辑 web.config? (2认同)