.NET Runtime Does Not Affect MVC Web Project

We are trying to set a timeout, and requests are simply not synchronized. We tried to establish several methods:

By placing this in the web.config file (both in the web.config application and in the views folder)

<httpRuntime executionTimeout="5" /> 

We made sure that we are not in debug mode

 <compilation debug="false" targetFramework="4.0"> 

We even tried to set the script timeout in the code (although it should be the same) and added Thread.Sleep for 3 minutes (to make sure that we were much higher than even the default timeout). And this action is still not a wait time:

  public ActionResult Index() { Server.ScriptTimeout = 5; Thread.Sleep(60 * 1000 * 3); return View(); } 

This happens on several machines, and I even went on to create a completely new solution, only with the above changes from the template, and the new IIS web application pool ... still cannot get a timeout.

Are there any simple configuration settings that we are missing? It seems that this should be easy to do ...

+6
source share
1 answer

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"> 
+5
source

Source: https://habr.com/ru/post/921342/


All Articles