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

问题描述 投票:0回答:1
  • 从Visual Studio中选择创建一个新项目。选择ASP.NET Core 3.1
  • 在IIS中发布和托管
  • 增加上传文件大小这个代码。
public void ConfigureServices(IServiceCollection services)
        {
            services.Configure<IISServerOptions>(options =>
            {
                options.MaxRequestBodySize = 314572800;
            });

            services.AddControllersWithViews();
        }

和web配置。

<security>
    <requestFiltering>
      <!-- This will handle requests up to 300MB -->
      <requestLimits maxAllowedContentLength="314572800" />
    </requestFiltering>
  </security>

上面的应用是正确的,但默认的超时是2分钟。

asp core 3.1托管在iis中如何增加超时?

注:我的web.config

<aspNetCore processPath="dotnet" arguments=".\AspCoreTestFileUpload.dll" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" hostingModel="inprocess" />

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

https:/docs.microsoft.comen-usaspnetcorehost-and-deployaspnet-core-module?view=aspnetcore-3.1#attributes-of-theaspnetcore-element。

我必须使用inprocess hostingModel。

asp.net-core iis publish request-timed-out
1个回答
0
投票

你可以在下面的iis设置中增加请求超时。

1)打开iis管理器,选择你的网站。

2)从操作面板中选择提前设置。

3)在限制部分的高级设置中设置连接超时值。

enter image description here


0
投票

用以下代码解决

services.Configure<IISServerOptions>(options =>
            {
                options.MaxRequestBodySize = int.MaxValue;
            });

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

            services.AddControllersWithViews();

© www.soinside.com 2019 - 2024. All rights reserved.