如何在ASP .NET Core 3.1中设置请求超时 [英] how set the request timeout in asp .net core 3.1
本文介绍了如何在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;
});
这篇关于如何在ASP .NET Core 3.1中设置请求超时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文