Question

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?

Was it helpful?

Solution

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?)

OTHER TIPS

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

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

HttpContext.Current.Server.ScriptTimeout = 300;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top