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;
});
推荐阅读
- html - 背景和悬停效果
- elasticsearch - Elasticsearch:如何在过滤器上下文中编写“OR”子句?
- java - java 7: 响应.flushBuffer(); 不在浏览器中下载 csv
- r - 在不绘图的情况下扩展轴限制(以按 x 单位对齐两个绘图)
- ios - 自定义钥匙串警报操作
- html - 按钮固定位置
- xamarin.forms - 如何将值从视图模型传递到模型?
- javascript - 在javascript中需要一个正则表达式
- react-native - 如何使用 Expo 修复 ReactNative 中的“未捕获错误:不变违规”错误?
- react-native - 使用地理定位 react-native 时出错