Problem:
I need to create a web project with a controller that times out.
What I have done:
.
<?xml version="1.0"?>
<configuration>
<system.web>
<httpRuntime executionTimeout="1" />
<compilation debug="false" />
<httpModules>
<add name="UrlRoutingModule" type="System.Web.Routing.UrlRoutingModule, System.Web.Routing, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
</httpModules>
</system.web>
</configuration>
.
public class DefaultController : Controller
{
public EmptyResult Index()
{
System.Threading.Thread.Sleep(3000);
Response.Write("ScriptTimeout: " + HttpContext.Server.ScriptTimeout);
return new EmptyResult();
}
}
When run, the server sleeps for 3 seconds, then returns the response without any timeout error. ScriptTimeout value is 1.
Question:
Any idea what went wrong?
Do you want a 408 Request Timeout HTTP status code?
public ActionResult Index()
{
return new HttpStatusCodeResult(408);
}
http://en.wikipedia.org/wiki/List_of_HTTP_status_codes
The executionTimeout attribute on the <httpRuntime/> element is only taken into account if debug="false" on the <compilation/> element.
Try removing the debug attribute or explicitly setting it to false. Of course, you'll have to run your application without debugging to test it.
See http://msdn.microsoft.com/en-gb/library/vstudio/e1f13641(v=vs.100).aspx for more details.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With