Asp.net-Core
如何在asp .net core 3.1中設置請求超時
- 從 Visual Studio 中選擇創建一個新項目。選擇 ASP.NET Core 3.1
- 在 IIS 中發布和託管
- 增加上傳文件大小此程式碼:
public void ConfigureServices(IServiceCollection services) { services.Configure<IISServerOptions>(options => { options.MaxRequestBodySize = 314572800; }); services.AddControllersWithViews(); }和網路配置:
<security> <requestFiltering> <!-- This will handle requests up to 300MB --> <requestLimits maxAllowedContentLength="314572800" /> </requestFiltering> </security>以上正確適用,但預設超時為 2 分鐘
如何增加 IIS 中託管的 ASP.NET Core 3.1 應用程序的超時時間?
注意:我的 web.config
<aspNetCore processPath="dotnet" arguments=".\AspCoreTestFileUpload.dll" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" hostingModel="inprocess" />對於 requestTimeout :不適用於程序內託管。對於程序內託管,模組等待應用程序處理請求。
我必須使用程序內託管模型
問題已解決:
在網路配置中:
<security> <requestFiltering> <!-- This will handle requests up to 300MB --> <requestLimits maxAllowedContentLength="314572800" /> </requestFiltering> </security>在 asp core 3.1 ConfigureServices 中:我不明白原因,但這段程式碼解決了問題
services.Configure<FormOptions>(options => { options.ValueLengthLimit = int.MaxValue; options.MultipartBodyLengthLimit = long.MaxValue; // <-- ! long.MaxValue options.MultipartBoundaryLengthLimit = int.MaxValue; options.MultipartHeadersCountLimit = int.MaxValue; options.MultipartHeadersLengthLimit = int.MaxValue; });