8

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

spottedmahn
  • 14,823
  • 13
  • 108
  • 178
DrShaffopolis
  • 1,088
  • 1
  • 11
  • 14
  • 2
    Oddly enough, if we put the Thread.Sleep in Global.asax.cs --> Application_BeginRequest it DOES timeout, but not when the Thread.Sleep is in the action. – DrShaffopolis Jul 25 '12 at 19:44
  • Looks like this thread addresses your question: http://forums.asp.net/p/1715081/4723882.aspx/1?Re+web+config+executionTimeout+not+working+in+ASP+NET+MVC – Phil Sandler Jul 25 '12 at 19:50

1 Answers1

8

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">
DrShaffopolis
  • 1,088
  • 1
  • 11
  • 14