1 发布后,修改webconfig文件
<?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="dotnet" arguments=".TAX.WebAPI.dll" stdoutLogEnabled="false" stdoutLogFile=".logsstdout" />
<security>
<requestFiltering>
<requestLimits maxAllowedContentLength="1073741822" /><!-- 1GB-->
</requestFiltering>
</security>
</system.webServer>
</location>
</configuration>
<!--ProjectGuid: B5091FF6-AC7A-47D5-8BF3-8604AECA5211-->
2.在Startup的ConfigureServices中添加代码段
-
//上传文件大小限制Kestrel设置
-
services.Configure<KestrelServerOptions>(options =>
-
{
-
// Set the limit to 256 MB
-
options.Limits.MaxRequestBodySize = 268435456;
-
});
-
//上传文件大小限制IIS设置
-
services.Configure<IISServerOptions>(options =>
-
{
-
options.MaxRequestBodySize = long.Parse(Configuration.GetSection("Kestrel").Value);
});
3 -------
public void ConfigureServices(IServiceCollection services) { services.AddMvc(config => config.Filters.Add<AuthFilter>()) .AddJsonOptions(options => options.SerializerSettings.ContractResolver = new DefaultContractResolver()) .SetCompatibilityVersion(CompatibilityVersion.Version_2_2); //解决文件上传Multipart body length limit 134217728 exceeded services.Configure<FormOptions>(x => { x.ValueLengthLimit = int.MaxValue; x.MultipartBodyLengthLimit = int.MaxValue; x.MemoryBufferThreshold = int.MaxValue; }); }