Berbagi teknologi

inti asp.net menghindari volume data isi permintaan yang berlebihan

2024-07-12

한어Русский языкEnglishFrançaisIndonesianSanskrit日本語DeutschPortuguêsΕλληνικάespañolItalianoSuomalainenLatina

metode 1,

penghindaran global
Perkenalkan paket dotnet tambahkan paket Microsoft.AspNetCore.Http.Features

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
    });

    // 其他配置和服务注册...
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14

Metode 2

untuk suatu metode

   [HttpPost("specific-method")]
    [RequestSizeLimit(10_000_000)] // 10 MB
    public IActionResult PostSpecificMethod([FromBody] MyModel model)
    {
        // 处理请求
        return Ok();
    }
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7