[英]How to increase the limit on the size of the uploaded file?
I'm use ABP Zero Core MVC template (ASP.Net Core 2.x, MVC, jQuery) version 4.2.0. 我正在使用ABP零核心MVC模板(ASP.Net Core 2.x,MVC,jQuery)版本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.
当我尝试使用AJAX将文件上传到控制器时,出现HTTP 404.13错误,该错误指示已超过最大文件大小。 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>();
}
Have you tried to decorate the controller action
with [RequestSizeLimit(YOUR_MAX_TOTAL_UPLOAD_SIZE)]
along with the changes in Startup.cs
? 您是否尝试过使用
[RequestSizeLimit(YOUR_MAX_TOTAL_UPLOAD_SIZE)]
装饰控制器action
以及Startup.cs
的更改?
services.Configure<FormOptions>(opt =>
{
opt.MultipartBodyLengthLimit = YOUR_MAX_TOTAL_UPLOAD_SIZE;
});
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. 顺便说一句,如果您打算将应用程序托管在IIS上,则可以将
web.config
文件添加到项目中并在其中配置upload size
,而不是在IIS服务器上进行配置。
EDIT: as @XelaNimed 's comment, adding the web.config
file along with editing the startup.cs
, got the code working. 编辑:作为@XelaNimed的注释,添加
web.config
文件以及编辑startup.cs
,使代码正常工作。
<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>
Try this 尝试这个
Startup.cs Startup.cs
public void ConfigureServices(IServiceCollection services)
{
//add to beginning of the method...
services.Configure<FormOptions>(x =>
{
x.ValueLengthLimit = int.MaxValue;
x.MultipartBodyLengthLimit = int.MaxValue;
x.MultipartHeadersLengthLimit = int.MaxValue;
});
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.