[英]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.