3

Problem:

I need to create a web project with a controller that times out.

What I have done:

  • Create a new web application
  • Empty the web.config, and write the values below:

.

<?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>
  • Write the following code to the controller:

.

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?

2 Answers 2

1

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

1
  • 1
    No, not really. Based on the example above, I want to make a one second timeout page/site. Jul 20, 2011 at 17:39
1

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.