问题:
我需要创建一个带有超时控制器的Web项目。
我做了什么:
<?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();
}
}
运行时,服务器休眠3秒钟,然后返回响应,没有任何超时错误。 ScriptTimeout值为1.
问题:
知道出了什么问题吗?
答案 0 :(得分:1)
您想要一个408 Request Timeout
HTTP状态代码吗?
public ActionResult Index()
{
return new HttpStatusCodeResult(408);
}
答案 1 :(得分:1)
只有executionTimeout
元素<httpRuntime/>
上的debug="false"
才会考虑<compilation/>
元素的{{1}}属性。
尝试删除debug属性或将其明确设置为false。当然,您必须在没有调试的情况下运行应用程序来测试它。
有关详细信息,请参阅http://msdn.microsoft.com/en-gb/library/vstudio/e1f13641(v=vs.100).aspx。