如何增加上传文件的大小限制?
How to increase the limit on the size of the uploaded file?
我正在使用 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. and here 我找到了类似问题的解决方案并尝试如此准确地解决了它,但它们要么不符合所使用的模式,要么我做错了什么。
如何在零核心中增加最大上传文件大小?
// *.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>();
}
试试这个
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;
});
}
您是否尝试过用 [RequestSizeLimit(YOUR_MAX_TOTAL_UPLOAD_SIZE)]
装饰控制器 action
以及 Startup.cs
中的变化?
services.Configure<FormOptions>(opt =>
{
opt.MultipartBodyLengthLimit = YOUR_MAX_TOTAL_UPLOAD_SIZE;
});
顺便说一句,如果您打算在 IIS 上托管该应用程序,您可以将 web.config
文件添加到您的项目并在那里配置 upload size
,而不是在 IIS 服务器上配置它。
编辑:作为 @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>
我正在使用 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.
如何在零核心中增加最大上传文件大小?
// *.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>();
}
试试这个
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;
});
}
您是否尝试过用 [RequestSizeLimit(YOUR_MAX_TOTAL_UPLOAD_SIZE)]
装饰控制器 action
以及 Startup.cs
中的变化?
services.Configure<FormOptions>(opt =>
{
opt.MultipartBodyLengthLimit = YOUR_MAX_TOTAL_UPLOAD_SIZE;
});
顺便说一句,如果您打算在 IIS 上托管该应用程序,您可以将 web.config
文件添加到您的项目并在那里配置 upload size
,而不是在 IIS 服务器上配置它。
编辑:作为 @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>