asp .net core 避免请求body数据量过大

方法1,

全局避免

引入包 dotnet add package Microsoft.AspNetCore.Http.Features

csharp 复制代码
using Microsoft.AspNetCore.Http.Features;

public void ConfigureServices(IServiceCollection services)
{
    services.Configure<FormOptions>(options =>
    {
        // 设置允许的最大请求体大小
        options.MultipartBodyLengthLimit = 60000000; // 60 MB
        options.ValueLengthLimit = 60000000; // 60 MB
        options.MemoryBufferThreshold = 60000000; // 60 MB
    });

    // 其他配置和服务注册...
}

方法2

针对某个方法

csharp 复制代码
   [HttpPost("specific-method")]
    [RequestSizeLimit(10_000_000)] // 10 MB
    public IActionResult PostSpecificMethod([FromBody] MyModel model)
    {
        // 处理请求
        return Ok();
    }
相关推荐
weixin_379880924 天前
.Net Core WebApi集成Swagger
java·服务器·.netcore
The Future is mine6 天前
.Net Core 在Linux系统下创建服务
linux·运维·.netcore
*长铗归来*7 天前
ASP.NET Core Web API 中控制器操作的返回类型及Swagger
后端·c#·asp.net·.netcore
IDOlaoluo7 天前
VS2017 安装 .NET Core 2.2 SDK 教程(包括 dotnet-sdk-2.2.108-win-x64.exe 安装步骤)
.netcore
csdn_aspnet15 天前
使用 Entity Framework Code First 方法创建 ASP.NET Core 5.0 Web API
.netcore·webapi
小先生81215 天前
.NET Core项目中 Serilog日志文件配置
c#·.netcore
爱吃香蕉的阿豪15 天前
.NET Core 中 System.Text.Json 与 Newtonsoft.Json 深度对比:用法、性能与场景选型
数据库·json·.netcore
csdn_aspnet15 天前
ASP.NET Core 10.0 的主要变化
.netcore
csdn_aspnet18 天前
在 C# .NETCore 中使用 MongoDB(第 1 部分):驱动程序基础知识和插入文档
mongodb·.netcore
csdn_aspnet18 天前
在 C# .NETCore 中使用 MongoDB(第 3 部分):跳过、排序、限制和投影
mongodb·c#·.netcore