Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 700
Kyle West Avatar asked Feb 23 '09 21:02

Kyle West


People also ask

How can change session timeout in ASP.NET MVC?

Open the web. config file, then increase the value in minutes by using the time out attribute of SessionState element. By default, the session timeout value is 20 minutes. Also in your case if you are using forms authentication, please check the timeout value.

What is session timeout in ASP.NET MVC?

By default, the ASP.NET MVC session timeout value is 20 minutes. For automatic Logout from Asp.net Identity when the user is Inactive, you have to use the below code in the Startup. cs file. The login page will be automatically redirected after 30 mins if the user is inactive.


2 Answers

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

like image 54
AnthonyWJones Avatar answered Sep 25 '22 23:09

AnthonyWJones


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

like image 38
Wojtek Trelak Avatar answered Sep 21 '22 23:09

Wojtek Trelak