如何在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分钟
The above applies correctly but defualt timeout is 2 min
如何在iis中托管的asp core 3.1中增加超时时间?
How increase timeout in asp core 3.1 hosted in iis?
注意:我的web.config
Note : my web.config
<aspNetCore processPath="dotnet" arguments=".\AspCoreTestFileUpload.dll" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" hostingModel="inprocess" />
对于requestTimeout: 不适用于进程内托管.对于进程内托管,该模块等待应用处理请求.
for requestTimeout : Doesn't apply to in-process hosting. For in-process hosting, the module waits for the app to process the request.
答
问题已解决:
在网络配置中:
<security>
<requestFiltering>
<!-- This will handle requests up to 300MB -->
<requestLimits maxAllowedContentLength="314572800" />
</requestFiltering>
</security>
和在asp核心3.1 ConfigureServices中: 我不明白原因,但是这段代码解决了问题
and in asp core 3.1 ConfigureServices : I did not understand the reason, but this piece of code solved the problem
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;
});