我使用ABP Zero Core MVC模板(ASP.Net Core 2.x,MVC,jQuery)版本4.2.0。当我尝试使用 AJAX 将文件上传到控制器时,收到 HTTP 404.13 错误,这表明超出了最大文件大小。 这里和这里我找到了类似问题的解决方案,并尝试解决它,但它们要么不符合所使用的模式,要么我做错了什么。
如何增加零核中的最大上传文件大小?
// *.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>();
}
您是否尝试过用
action
来装饰控制器[RequestSizeLimit(YOUR_MAX_TOTAL_UPLOAD_SIZE)]
以及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>
试试这个
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;
});
}
我的网络服务器 (
web.config
) 上的 E:\\WebServer\\DBBweb\\web.config
文件遇到问题。我意识到再次超出了最大文件大小限制。以下是我为识别和解决问题所采取的步骤:
web.config
文件的大小为251KB,大于允许的最大文件大小250KB。HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\InetStp
。MaxWebConfigFileSizeInKB
的 DWORD 值,并将其值设置为大于 251KB 的数字。HKEY_LOCAL_MACHINE\\SOFTWARE\\Wow6432Node\\Microsoft\\InetStp
。此键与上一个键相同,但在路径中包含 Wow6432Node
。必须对两个密钥执行此过程,因为该网站正在利用 32 位兼容性。
尽管如此,我和团队仍然建议不要在
web.config
中添加客户服务。我们建议改用 APIHANDLER
,它充当 web.config
的扩展。
任何人都可以提供额外的解决方案或确认这是否是处理
web.config
中超过最大文件大小问题的最有效方法?另外,任何人都可以阐明使用 APIHANDLER
相对于直接在 web.config
中添加客户服务的好处吗?
预先感谢您的协助。