如何在 ASP.NET Core 5 中使用 Server.ScriptTimeout(从 .NET 框架迁移到 .NET 5)

How to use Server.ScriptTimeout in ASP.NET Core 5 (migration from .NET framework to .NET 5)

感谢阅读我的post。

最初,我在 .NET 框架上使用 ASP.NET MVC,但我想迁移到 .NET 5。

然而,这行代码:

filterContext.Controller.ControllerContext.HttpContext.Server.ScriptTimeout = TimeoutSeconds;

在 .NET 5 中不工作 - 如何解决?

您似乎正试图在 asp.net 5 上设置与之前在 asp.net MVC 上的 Server.ScriptTimeout 相同的相应功能。如果是这种情况,您可以在 IIS 和 Program.cs 中使用 ServertimeOut 来实现,您可以按以下方式设置,

public static IHostBuilder CreateHostBuilder(string[] args) =>
            Host.CreateDefaultBuilder(args)
                .ConfigureWebHostDefaults(webBuilder =>
                {
                    webBuilder.UseStartup<Startup>()
                    .UseKestrel(option =>
                    {
                        option.Limits.KeepAliveTimeout = TimeSpan.FromMinutes(10);
                        option.Limits.RequestHeadersTimeout = TimeSpan.FromMinutes(10);
                    })
                    .Build();
                });

Note :

You could refer to official document here for futher reference, additionaly, please share your code in minimal reproducible way so that we can reproduce the issue instead of screenshoot. it.

You can do that on IIS as well :

对于 IIS,请按照以下步骤做同样的事情:

  1. 打开您的 IIS
  2. 转到“站点”选项。
  3. 右击鼠标。
  4. 然后打开属性“管理网站”。
  5. 然后点击“高级设置”。
  6. 展开“限制”部分,您可以在此处设置“连接超时”

为了更清楚起见,这里是屏幕截图:

希望以上指南能对您有所帮助。