我正在尝试在我的.NET Core v3.1 Blazor应用程序中上传多个文件,但我无法通过30MB的限制。
搜索后,我找到了Increase upload file size in Asp.Net core,并尝试了其中的建议,但并没有奏效。
所有找到的解决方案都涉及更改web.config文件,但我没有该文件。
此外,我的应用程序在Visual Studio 2019中进行开发运行,但也将作为WebApp在Azure上运行。
这是我的设置:
program.cs
public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStartup<Startup>().ConfigureKestrel((context, options) =>
{
options.Limits.MaxRequestBodySize = null;
});
});
上传控制器UploadController.cs
[Authorize]
[DisableRequestSizeLimit]
public class UploadController : BaseApiController
在Startup.cs中配置服务
services.AddSignalR(e => e.MaximumReceiveMessageSize = 102400000)
.AddAzureSignalR(Configuration["Azure:SignalR:ConnectionString"]);
services.Configure<FormOptions>(options =>
{
options.ValueLengthLimit = int.MaxValue;
options.MultipartBodyLengthLimit = long.MaxValue; // <-- !!! long.MaxValue
options.MultipartBoundaryLengthLimit = int.MaxValue;
options.MultipartHeadersCountLimit = int.MaxValue;
options.MultipartHeadersLengthLimit = int.MaxValue;
});
services.Configure<IISServerOptions>(options =>
{
options.MaxRequestBodySize = int.MaxValue;
});
在 Startup.cs 文件中配置
app.Use(async (context, next) =>
{
context.Features.Get<IHttpMaxRequestBodySizeFeature>()
.MaxRequestBodySize = null;
await next.Invoke();
});
我有遗漏设置吗?难以置信这需要如此困难。