如何增加上传文件大小的限制? [英] How to increase the limit on the size of the uploaded file?

查看:325
本文介绍了如何增加上传文件大小的限制?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是 ABP零核MVC 模板(ASP.Net Core 2.x,MVC,jQuery )版本4.2.0.当我尝试使用AJAX将文件上传到控制器时,出现 HTTP 404.13 错误,表明已超过最大文件大小. 此处

I'm use ABP Zero Core MVC template (ASP.Net Core 2.x, MVC, jQuery) version 4.2.0. When I try to upload a file using the AJAX to controller, I get an HTTP 404.13 error, which indicates that the maximum file size is exceeded. Here and here I found solutions to similar problem and try it solved so ajust, but they either do not fit the pattern used, or I'm doing something wrong.

如何在零核心"中增加最大上传文件大小?

How to increase the maximum upload file size in Zero Core?

// *.Web.Host\Startup\Program.cs 
// *.Web.Mvc\Startup\Program.cs
public static IWebHostBuilder CreateWebHostBuilder(string[] args) {
    return WebHost.CreateDefaultBuilder(args)
        .UseKestrel(options => { 
            // no effect...  I can only small files uploaded
            options.Limits.MaxRequestBodySize = 1024 * 1024 * 1024; 
        })
        .UseStartup<Startup>();
}

推荐答案

您是否尝试过用[RequestSizeLimit(YOUR_MAX_TOTAL_UPLOAD_SIZE)]装饰控制器action以及Startup.cs中的更改?

Have you tried to decorate the controller action with [RequestSizeLimit(YOUR_MAX_TOTAL_UPLOAD_SIZE)] along with the changes in Startup.cs?

services.Configure<FormOptions>(opt =>
{
    opt.MultipartBodyLengthLimit = YOUR_MAX_TOTAL_UPLOAD_SIZE;
});


顺便说一句,如果您打算将应用程序托管在IIS上,则可以将web.config文件添加到项目中并在其中配置upload size,而不是在IIS服务器上进行配置.


btw, if you are planning to host the app on IIS, you can add web.config file to your project and configure the upload size there, rather than configuring it on the IIS server.

作为 @XelaNimed 的注释,添加web.config文件并编辑startup.cs,使代码正常工作.

as @XelaNimed's comment, adding the web.config file along with editing the startup.cs, got the code working.

<configuration>
  <location path="." inheritInChildApplications="false">
   <system.webServer>
     <handlers>
       <add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified" />
     </handlers>
     <aspNetCore processPath="%LAUNCHER_PATH%" arguments="%LAUNCHER_ARGS%" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout">
       <environmentVariables />
     </aspNetCore>
   </system.webServer>
 </location>
 <system.webServer>
   <security>
      <requestFiltering>
        <requestLimits maxAllowedContentLength="YOUR_BYTES" />
       </requestFiltering>
    </security>
  </system.webServer>
</configuration>

这篇关于如何增加上传文件大小的限制?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆