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;
                });
            }
     
  • 相关阅读:
    一个web应用的诞生(4)
    一个web应用的诞生(7)
    一个web应用的诞生(6)
    HTTP状态码大全(转自wiki)
    十分钟搞懂什么是CGI
    HTTP真的很简单
    QT程序在发布的时候应注意的地方
    QT中获取选中的radioButton的两种方法
    WinEdit编辑器中中文乱码
    C++ lstrlen()
  • 原文地址:https://www.cnblogs.com/zhang-wenbin/p/10412442.html
Copyright © 2011-2022 走看看