How to set request timeout for one controller action in asp.net mvc application

I want to increase the request timeout for a specific controller action in my application. I know that I can do this in web.config for the entire application, but I would prefer to change it to just one action.

Web.config example:

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

How should I do it?

+70
asp.net-mvc asp.net-web-api
Feb 23 '09 at 21:48
source share
3 answers

You can install this programmatically in the controller: -

 HttpContext.Current.Server.ScriptTimeout = 300; 

Sets a timeout of 5 minutes instead of 110 seconds by default (what's the odd default value?)

+97
Feb 23 '09 at 22:11
source share
 <location path="ControllerName/ActionName"> <system.web> <httpRuntime executionTimeout="1000"/> </system.web> </location> 

It is probably best to set such values ​​in web.config instead of the controller. Hardcoding custom parameters is considered harmful.

+46
Dec 06 2018-11-17T00:
source share

I had to add "Current" using .NET 4.5:

 HttpContext.Current.Server.ScriptTimeout = 300; 
+16
May 19 '15 at 16:49
source share



All Articles