.NET Core 3 &IIS Express maxAllowedContentLength 不起作用 [英] .NET Core 3 & IIS Express maxAllowedContentLength not working
问题描述
我有一个 JavaScript 应用程序,它正在将文件发布到 .NET Core 3 Web API.
Web API 项目在 IIS Express 上本地运行.
I have a JavaScript application which is posting files to .NET Core 3 Web API.
Web API project works locally on IIS Express.
小于 30 MB 的文件工作正常,但大文件无法通过.
Files below 30 MB are working fine, but large files does not get through.
这里我试过了;
1- 使用新的 maxAllowedContentLength
值更新 %userprofile%my documentsiisexpressconfigapplicationhost.config
文件.
1- Update %userprofile%my documentsiisexpressconfigapplicationhost.config
file with new maxAllowedContentLength
value.
2- 将 RequestSizeLimit
属性添加到控制器操作.
2- Add RequestSizeLimit
attribute to Controller Action.
这里还有什么我遗漏的吗?
Is there anything else I am missing here?
推荐答案
我遇到了同样的问题(从 .NET Core 3 开始),首先找到了解决方法,然后找到了正确的解决方案.
I had the same problem (since .NET Core 3), and found a workaround first, then a proper solution.
解决方法:在您的 web.config 文件中,使用AspNetCoreModule"而不是AspNetCoreModuleV2",但您将不再受益于新模块的优势.
Workaround: in your web.config file, use "AspNetCoreModule" instead of "AspNetCoreModuleV2", but you no longer benefit from the advantages of the new module.
解决方案:将此添加到您的 startup.cs 文件
A solution: add this to your startup.cs file
services.Configure<IISServerOptions>(options =>
{
options.MaxRequestBodySize = int.MaxValue; // or your desired value
});
我在这里找到了这个信息:https://docs.microsoft.com/en-us/aspnet/core/host-and-deploy/iis/?view=aspnetcore-3.1#application-configuration.IIS 选项 > 进程内托管模型,然后属性MaxRequestBodySize".为此,您仍然需要将 web.config 配置为如下内容:
I found this info here: https://docs.microsoft.com/en-us/aspnet/core/host-and-deploy/iis/?view=aspnetcore-3.1#application-configuration. IIS options > In-process hosting model, then attribute "MaxRequestBodySize". For this to work, you still need to have your web.config configured with something like this:
<security>
<requestFiltering>
<requestLimits maxAllowedContentLength="2147483647" /> //or your desired value
</requestFiltering>
</security>
希望能帮到你!
这篇关于.NET Core 3 &IIS Express maxAllowedContentLength 不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!