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();
    }
相关推荐
1-1=08 天前
C# 数据结构和特殊类型
数据结构·c#·.net·.netcore
1-1=011 天前
C# IO和序列化
c#·.net·.netcore
宝桥南山12 天前
.NET 11 - 尝试一下Blazor中的新特性SupplyParameterFromTempData
microsoft·微软·c#·asp.net·.net·.netcore
1-1=013 天前
C# 特性(Attribute)
c#·.net·.netcore
淡海水14 天前
10-01-互操作-C#与C++边界的内存管理
unity·c#·游戏引擎·.netcore·gc
1-1=014 天前
C# 反射
c#·.net·.netcore
1-1=015 天前
C# 泛型
c#·.net·.netcore
淡海水17 天前
09-01-内存-Unity资源生命周期全景
unity·c#·游戏引擎·.netcore·gc
1-1=017 天前
.NET Core 编译技术
.net·.netcore
1-1=018 天前
.NET Core 文件系统
.net·.netcore·1024程序员节