How do I set the request timeout for one controller action in an asp.net mvc application

asp.net Mvcasp.net Web-Api

asp.net Mvc Problem Overview


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

Web.config example:

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

How do I do it?

asp.net Mvc Solutions


Solution 1 - asp.net Mvc

You can set this programmatically in the controller:-

HttpContext.Current.Server.ScriptTimeout = 300;

Sets the timeout to 5 minutes instead of the default 110 seconds (what an odd default?)

Solution 2 - asp.net Mvc

<location path="ControllerName/ActionName">
	<system.web>
		<httpRuntime executionTimeout="1000"/>
	</system.web>
</location>

Probably it is better to set such values in web.config instead of controller. Hardcoding of configurable options is considered harmful.

Solution 3 - asp.net Mvc

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

HttpContext.Current.Server.ScriptTimeout = 300;

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionKyle WestView Question on Stackoverflow
Solution 1 - asp.net MvcAnthonyWJonesView Answer on Stackoverflow
Solution 2 - asp.net MvcWojtek TrelakView Answer on Stackoverflow
Solution 3 - asp.net MvcPatrick MichalinaView Answer on Stackoverflow