We're trying to set a timeout, and requests just aren't timing out. We tried setting this several ways:
By putting this in the web.config (in both the application's web.config, and the one in the views folder)
<httpRuntime executionTimeout="5" />
We made sure that we were not in debug mode
<compilation debug="false" targetFramework="4.0">
We even tried setting a script timeout in code (even though it's supposed to be the same thing) and added a Thread.Sleep for 3 minutes (to make sure we were well above even the default timeout) And this action still does not time out:
public ActionResult Index()
{
Server.ScriptTimeout = 5;
Thread.Sleep(60 * 1000 * 3);
return View();
}
It's happening on multiple machines, and I even went to creating a brand new solution with only the above changes from the template, and a brand new IIS website application pool... still, can't get a timeout.
Is there some simple configuration setting we're missing? This seems like it should be easy to do...
executionTimeout attribute of httpRuntime element (in the web. config) can be used to change the request timeout duration for ASP.NET Application. executionTimeout value is specified in seconds. Default value is 110 seconds.
Remarks. The ExecutionTimeout property indicates the maximum number of seconds a request is allowed to execute before being automatically shut down by ASP.NET. The default is 110 seconds.
To add to the eventual solution: The link above has a way to force MVC to respect the timeout for the current HttpContext
System.Web.HttpContext.Current.GetType().GetField("_timeoutState", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic).SetValue(System.Web.HttpContext.Current, 1);
Because we wanted it to run on EVERY request, we created a global action filter for it
public class Timeoutter : ActionFilterAttribute
{
public override void OnActionExecuting(ActionExecutingContext filterContext)
{
System.Web.HttpContext.Current.GetType().GetField("_timeoutState", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic).SetValue(System.Web.HttpContext.Current, 1);
base.OnActionExecuting(filterContext);
}
}
And then to register it, in the app's global.asax:
public static void RegisterGlobalFilters(GlobalFilterCollection filters)
{
filters.Add(new Timeoutter());
}
Keep in mind this solution still requires the same 2 above lines in web.config
<httpRuntime executionTimeout="5" />
<compilation debug="false" targetFramework="4.0">
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With