C# 上传文件过大引起的报错

操作环境

Asp .Net Core 5.0

错误日志

Failed to read the request form. Request body too large.

解决方法

参照 https://www.cnblogs.com/zhang-wenbin/p/10412442.html

修改Startup.cs文件

public void ConfigureServices(IServiceCollection services)
{

	services.AddControllers();

	services.Configure<FormOptions>(x =>
	{
		x.ValueLengthLimit = int.MaxValue;
		x.MultipartBodyLengthLimit = int.MaxValue;
		x.MemoryBufferThreshold = int.MaxValue;
	});
	services.Configure<KestrelServerOptions>(options =>
	{
		options.Limits.MaxRequestBodySize = 1024 * 1024 * 1024;
	});
}
上一篇:【2021-12-31】将 [4, -4] 映射到为 [0, 1000]的空间


下一篇:C#随机数