![](/img/trans.png)
[英]ASP.NET Core returns 404 after resetting applicationhost.config
[英]ASP.NET Core web.config requestFiltering not overriding applicationhost.config
我正在尝试在我的 ASP.NET Core MVC 2.1 应用程序中将大文件上传到 API controller 操作。 为此,我一直试图弄清楚如何通过 IIS Express 来实现这一点,这就是我通过 Visual Studio 运行应用程序的方式。 正如所建议的,这应该可以通过将web.config
文件添加到项目根目录中,其中包含以下内容:
<?xml version="1.0" encoding="utf-8"?>
<!-- Configuration for IIS integration -->
<configuration>
<system.webServer>
<security>
<requestFiltering>
<!-- 2 GB -->
<requestLimits maxAllowedContentLength="2147483647" />
</requestFiltering>
</security>
</system.webServer>
</configuration>
但是,这没有任何效果,因为应用程序只是返回HTTP Error 404.13 - Not Found
,表明请求太大。 这些设置似乎被 IIS 锁定,因此web.config
没有覆盖它们。 是的,我还在 controller 操作中使用[DisableFormValueModelBinding]
和[DisableRequestSizeLimit]
等属性。
相反,我发现它可以通过在\.vs\config
文件夹中的applicationhost.config
中的站点中添加相同的配置来工作:
<location path="MySite">
<system.webServer>
<handlers>
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified" />
</handlers>
<aspNetCore processPath="%LAUNCHER_PATH%" arguments="%LAUNCHER_ARGS%" stdoutLogEnabled="false" startupTimeLimit="3600" requestTimeout="23:00:00" />
<httpCompression>
<dynamicTypes>
<add mimeType="text/event-stream" enabled="false" />
</dynamicTypes>
</httpCompression>
<!-- Everything above this point is auto-generated -->
<security>
<requestFiltering>
<!-- 2 GB -->
<requestLimits maxAllowedContentLength="2147483647" />
</requestFiltering>
</security>
</system.webServer>
</location>
然而,这个文件在 GIT 中没有被跟踪,而且将它添加到 GIT 似乎也不是一个好的解决方案。
为什么web.config
似乎不允许覆盖applicationhost.config
是否有一些安全原因或其他原因? 还是有我无法弄清楚的解决方案?
我有一个类似的问题,我用这个添加了一个 web.config
<configuration>
<system.webServer>
<security>
<requestFiltering>
<!-- This will handle requests up to 700MB (CD700) -->
<requestLimits maxAllowedContentLength="737280000" />
</requestFiltering>
</security>
</system.webServer>][1]][1]
</configuration>
发布得太早了。 上述解决方案适用于 iis 快递服务器,但不适用于 docker。 然后我更新了条目
public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseStartup<Startup>()
.UseKestrel(options =>
{
options.Limits.MaxRequestBodySize = 100000000; //100MB
});
然后用[RequestSizeLimit(100_000_000)]
装饰控制器
这些解决方案在本地解决并为我生产。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.