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 天前
使用DNGuard加密并打包C# .NET Core程序为单一EXE文件
网络·.netcore
武藤一雄2 天前
C#中常见集合都有哪些?
开发语言·微软·c#·.net·.netcore
武藤一雄3 天前
.NET 中常见计时器大全
microsoft·微软·c#·.net·wpf·.netcore
武藤一雄4 天前
[.NET] 中 System.Collections.Generic命名空间详解
windows·微软·c#·asp.net·.net·.netcore
van久8 天前
.Net Core 学习:Razor Pages中 HTML 表头字段的两种写法对比
学习·html·.netcore
武藤一雄8 天前
C# 万字拆解线程间通讯?
后端·微软·c#·.net·.netcore·多线程
武藤一雄9 天前
.NET中到底什么是SignalR (持续更新)
后端·微软·c#·asp.net·.net·.netcore·signalr
by__csdn9 天前
第二章 (.NET Core环境搭建)第二节( Visual Studio Code)
ide·vscode·c#·vue·asp.net·.net·.netcore
by__csdn9 天前
第二章 (.NET Core环境搭建)第三节( Visual Studio for Mac)
ide·kubernetes·c#·asp.net·.net·.netcore·visual studio
武藤一雄10 天前
C#:进程/线程/多线程/AppDomain详解
后端·微软·c#·asp.net·.net·wpf·.netcore