【发布时间】:2020-01-23 22:45:26
【问题描述】:
我正在尝试将大文件上传到我的 ASP.NET Core MVC 2.1 应用程序中的 API 控制器操作。为此,我一直试图弄清楚如何通过 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 并没有覆盖它们。是的,我还在控制器操作上使用了 [DisableFormValueModelBinding] 和 [DisableRequestSizeLimit] 等属性。
相反,我发现它可以通过在applicationhost.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,是否有一些安全原因或其他原因?或者有没有我想不通的解决方案?
【问题讨论】:
-
当它一定是一个非常普遍的问题时,不知道为什么没有答案。唉,我最终恢复到只使用 POST 而不是 GET,我想这更有意义。
标签: c# asp.net-core asp.net-core-mvc