To add to a possible solution: the link above has a way to force MVC to 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);
Since 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 global.asax application:
public static void RegisterGlobalFilters(GlobalFilterCollection filters) { filters.Add(new Timeoutter()); }
Keep in mind that this solution still requires the same 2 above lines in web.config
<httpRuntime executionTimeout="5" /> <compilation debug="false" targetFramework="4.0">
source share