asp.net-core.net-5asp.net-core-5.0

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


Thanks for reading my post.

enter image description here

Originally, I was using ASP.NET MVC on the .NET framework, but I want to migrate to .NET 5.

However, this line of code:

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

is not working in .NET 5 - how to solve that?


Solution

  • It seems you are trying to set corresponding functionality on asp.net 5 same as previously Server.ScriptTimeout on asp.net MVC. If that is the scenario you could achieve that using ServertimeOut in IIS and in Program.cs you can set as following way:

    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 further reference.

    You can do that on IIS as well:

    For IIS follow these steps to do same thing:

    1. Open your IIS
    2. Go to "Sites" option.
    3. right click on Mouse.
    4. Then open property "Manage Web Site".
    5. Then click on "Advance Settings".
    6. Expand section "Limits", here you can set your "connection time out"

    Here is the screenshots for better clarity:

    enter image description here

    enter image description here