如何从 ASP.NET Core IIS上传大文件一些配置

        使用ASP.NET Core上传文件,可以参考官方文档: 使用缓冲模型绑定上传小文件到物理存储

 
        默认情况下,Windows IIS 将maxRequestLengthmaxAllowedContentLength分别限制为 4096 KB 和 30,000,000 字节。要上传大于这些限制的文件,您需要覆盖网站根web.config文件中的默认设置并修改 ASP.NET Core 表单设置。
 
下面是一个如何修改Program.csweb.config文件以增加最大文件上传大小的示例:

Program.cs 

// using packages.
// ...
using Microsoft.AspNetCore.Http.Features;

var builder = WebApplication.CreateBuilder(args);

// Add services to the container.
// ...

builder.Services.Configure<IISServerOptions>(options=>
{
    // 1024MB
    options.MaxRequestBodySize = 104857600;
});

builder.Services.Configure<FormOptions>(options =>
{
    // 1024MB
    options.MultipartBodyLengthLimit = 104857600;
});

var app = builder.Build();

// ...

web.config 

<?xml version="1.0" encoding="utf-8"?>
<configuration>
    <system.web>
        <!-- change the max to 1024 MB -->
        <httpRuntime maxRequestLength="104857600" />
    </system.web>
    <system.webServer>
        <security>
            <requestFiltering>
                <!-- change the max to 1024 MB -->
                <requestLimits maxAllowedContentLength="104857600" />
            </requestFiltering>
        </security>
    </system.webServer>
</configuration>

如果您的应用程序也使用Kestrel设置,您还应该像这样覆盖Program.cs文件中的默认设置: 

// using packages.
// ...

var builder = WebApplication.CreateBuilder(args);

builder.Host.ConfigureWebHostDefaults(webBuilder =>
{
    webBuilder.ConfigureKestrel((context, options) =>
    {
        options.Limits.MaxRequestBodySize = 104857600;
    });
});

// Add services to the container.
// ...

如果您喜欢此文章,请收藏、点赞、评论,谢谢,祝您快乐每一天。 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

csdn_aspnet

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值