I have tried the following so far- 1) Added Custom attribute for handling timeout.
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);
}
}
Added following in Global.asax
filters.Add(new TimeOutFilter());
Used [TimeOutFilter] attribute to decorate the contoller
2) Added AsyncTimeout attribute to decorate the controller/Action as follows:
[AsyncTimeout(10)]
3) Set executionTimeout to a value in web.config file.
<httpRuntime targetFramework="4.5" maxRequestLength="10240" executionTimeout="10" />
4) Set HttpContext.Server.ScriptTimeout to some value in the controller.
HttpContext.Server.ScriptTimeout = 10;
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.
I am looking for getting or triggering an exception when the request timeout happens.
Can somebody please let me know if there is any way we can do this?