2

Where to set request timeout on certain ASP.NET controller that has this timeout value? Is it in the constructor of the controller or somewhere else?

 System.Web.HttpContext.Current.Server.ScriptTimeout = 50;
Mike Flynn
  • 22,342
  • 54
  • 182
  • 341

2 Answers2

1

Since ScriptTimeout is an application-wide static setting, the only sensible place to set it would be at application startup.

Alternatively, you could set it in the web.config file.

<configuration>
...

<system.web>
   <httpRuntime executionTimeout="600" />

Reference: http://www.beansoftware.com/ASP.NET-FAQ/Change-Script-Timeout.aspx

NightOwl888
  • 55,572
  • 24
  • 139
  • 212
  • Bear in mind that the value of executionTimeout is in seconds, and will only have an effect if the "debug" attribute of the tag (under ) is set to "false", as stated in [this answer](https://stackoverflow.com/a/10650168/2287555). [Documentation](https://learn.microsoft.com/en-us/previous-versions/dotnet/netframework-2.0/e1f13641(v=vs.80)?redirectedfrom=MSDN) – Pona Oct 30 '19 at 15:44
  • 1
    This is not correct. Setting `ScriptTimeout` only has an effect for the current request. E.g. also mentioned in comment ScriptTimeout https://stackoverflow.com/a/579599/1059776 – Paul B. Aug 24 '20 at 10:34
0

If you want to apply the timeout to all actions of the controller setting ScriptTimeout seems like a good choice.

One exception would be if the upload duration may already exceed the application-wide executionTimeout setting. In that case the timeout occurs before execution reaches the controller and therefore the constructor won't have a chance to make the setting.

A workaround in this scenario is setting ScriptTimeout in Application_BeginRequest after analyzing HttpContext.Current.Request.Path.

Paul B.
  • 2,394
  • 27
  • 47