zoukankan      html  css  js  c++  java
  • .net core 上传文件大小限制 webconfig

    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中添加代码段

    1. //上传文件大小限制Kestrel设置
    2. services.Configure<KestrelServerOptions>(options =>
    3. {
    4. // Set the limit to 256 MB
    5. options.Limits.MaxRequestBodySize = 268435456;
    6. });
    7. //上传文件大小限制IIS设置
    8. services.Configure<IISServerOptions>(options =>
    9. {
    10. 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;
                });
            }
     
  • 相关阅读:
    Flutter | 如何优雅的解决依赖版本冲突
    Flutter包依赖冲突解决方法
    Cannot run with sound null safety because dependencies don't support null safety
    软件工程实践2019第三次作业
    【题解】洛谷 P3704 [SDOI2017]数字表格
    关于学历和素质成正比的隐晦思考
    斐波那契数列通项公式
    某不知名比赛游记
    CCPC-final 2020 北京游记
    EC-final 2020-2021 西安游记
  • 原文地址:https://www.cnblogs.com/zhang-wenbin/p/10412442.html
Copyright © 2011-2022 走看看