如何在asp .net core 3.1中设置请求超时

sbr*_*sbr 6 iis publish request-timed-out asp.net-core

  • 从 Visual Studio 中选择创建新项目。选择 ASP.NET Core 3.1
  • 在 IIS 中发布和托管
  • 增加上传文件大小此代码:
public void ConfigureServices(IServiceCollection services)
{
    services.Configure<IISServerOptions>(options =>
    {
        options.MaxRequestBodySize = 314572800;
    });

    services.AddControllersWithViews();
}
Run Code Online (Sandbox Code Playgroud)

和网络配置:

<security>
    <requestFiltering>
      <!-- This will handle requests up to 300MB -->
      <requestLimits maxAllowedContentLength="314572800" />
    </requestFiltering>
</security>
Run Code Online (Sandbox Code Playgroud)

以上正确适用,但默认超时为 2 分钟

如何增加 IIS 中托管的 ASP.NET Core 3.1 应用程序的超时时间?

注意:我的 web.config

<aspNetCore processPath="dotnet" arguments=".\AspCoreTestFileUpload.dll" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" hostingModel="inprocess" />
Run Code Online (Sandbox Code Playgroud)

对于 requestTimeout :不适用于进程内托管。对于进程内托管,模块等待应用程序处理请求。

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

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

sbr*_*sbr 6

问题已解决:

在网络配置中:

<security>
    <requestFiltering>
      <!-- This will handle requests up to 300MB -->
      <requestLimits maxAllowedContentLength="314572800" />
    </requestFiltering>
</security>
Run Code Online (Sandbox Code Playgroud)

在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;
});
Run Code Online (Sandbox Code Playgroud)