title: How to handle a request timeout in ASP.NET MVC5 application?
body: <p>I have tried the following so far-
  1) Added Custom attribute for handling timeout.</p>
  
  <pre><code> public class TimeOutFilter : 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);
      }
  }
  </code></pre>
  
  <p>Added following in Global.asax</p>
  
  <pre><code>filters.Add(new TimeOutFilter());
  </code></pre>
  
  <p>Used [TimeOutFilter] attribute to decorate the contoller</p>
  
  <p>2) Added AsyncTimeout attribute to decorate the controller/Action as follows:</p>
  
  <pre><code>[AsyncTimeout(10)]
  </code></pre>
  
  <p>3) Set executionTimeout to a value in web.config file.</p>
  
  <pre><code>&lt;httpRuntime targetFramework="4.5" maxRequestLength="10240" executionTimeout="10" /&gt;
  </code></pre>
  
  <p>4) Set HttpContext.Server.ScriptTimeout to some value in the controller.</p>
  
  <pre><code>HttpContext.Server.ScriptTimeout = 10;
  </code></pre>
  
  <p>Using the steps in point 1, I was able to redirect the user to Login screen on request timeout. But this is not what I am looking for.</p>
  
  <p>I am looking for getting or triggering an exception when the request timeout happens.</p>
  
  <p>Can somebody please let me know if there is any way we can do this?</p>