首页 > 解决方案 > 如何在asp .net core 3.1中设置请求超时

问题描述

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 :不适用于进程内托管。对于进程内托管,模块等待应用程序处理请求。

https://docs.microsoft.com/en-us/aspnet/core/host-and-deploy/aspnet-core-module?view=aspnetcore-3.1#attributes-of-the-aspnetcore-element

我必须使用进程内托管模型

标签: asp.net-coreiispublishrequest-timed-out

解决方案


问题已解决:

在网络配置中:

<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;
});

推荐阅读