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;
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;
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
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
.