.net core部署到ubuntu 上传文件超过30MB

时间:2023-03-08 22:23:52

默认的上传文件不能超过30MB,需要修改几个地方

一、web.config中添加配置

<requestLimits maxAllowedContentLength="2147483647" ></requestLimits>

(1)如果是开发环境,通过IIS Express添加

.net core部署到ubuntu 上传文件超过30MB

.net core部署到ubuntu 上传文件超过30MB

(2)如果是生产环境,添加到发布后的web.config中

在标签<system.webServer>中加入<security>内容

<?xml version="1.0" encoding="utf-8"?>
<configuration>
<location path="." inheritInChildApplications="false">
<system.webServer>
<handlers>
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified" />
</handlers>
<aspNetCore processPath=".\ZhiRen.Tourism.UI" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" />
<security>
<requestFiltering >
<requestLimits maxAllowedContentLength="2147483647" ></requestLimits>
</requestFiltering>
</security>
</system.webServer>
</location>
</configuration>
<!--ProjectGuid: 74eb1354-a638-4903-8784-2a74d874e010-->

  

二、在startup的ConfigureServices方法中

            services.Configure<FormOptions>(options =>
{
//设置上传文件大小限制
options.ValueLengthLimit = int.MaxValue;
options.MultipartBodyLengthLimit = int.MaxValue;
});

  

三、在保存文件的Controller的Action上加标签

        [RequestSizeLimit(1024_000_000)]
//[DisableRequestSizeLimit] //或者取消大小的限制
[HttpPost]
public async Task<IActionResult> Create(VideoMultipleLanguage ml, IFormCollection fc)
{
}

  

四、修改Nginx的配置文件

位置:/etc/nginx/nginx.conf

在http{}中加入

client_max_body_size 1000m;

建议修改连接时间

keepalive_timeout 1800;

.net core部署到ubuntu 上传文件超过30MB