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;

2 Answers 2

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

Sign up to request clarification or add additional context in comments.

2 Comments

Bear in mind that the value of executionTimeout is in seconds, and will only have an effect if the "debug" attribute of the tag <compilation> (under <system.web>) is set to "false", as stated in this answer. Documentation
This is not correct. Setting ScriptTimeout only has an effect for the current request. E.g. also mentioned in comment ScriptTimeout stackoverflow.com/a/579599/1059776
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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.