Exception type: HttpException Exception message: Request timed out.
微软互联网开发支持通过本文主要向大家介绍了Exception type: HttpException Exception message: Request timed out. 等相关知识,希望对您有所帮助,也希望大家支持linkedu.com www.linkedu.com
问题描述
超时问题发生时应用程序事件日志会出现以下警告。
通常这种问题发生的原因是由于请求的执行时间超过了服务器端配置的超时时间。在配置文件中可以通过httpRuntime/executionTimeout属性设置此最大超时时间(.Net 2.0中默认为110 秒)。
Event Type: Warning Event Source: ASP.NET 2.0.50727.0 Event Category: Web Event Event ID: 1309 Event code: 3001 Event message: The request has been aborted. Event sequence: 2 Event occurrence: 1 Event detail code: 0 ... Exception information: Exception type: HttpException Exception message: Request timed out.
问题重现
创建一个命名为sleep.aspx的ASPX页面。
<%@ Page Language="C#" %> <%@ import Namespace="System.Diagnostics" %> <script runat="server"> protected void Page_Load(object sender, EventArgs e) { DateTime time = DateTime.Now; Response.Write(String.Format("Time: {0}:{1}:{2}", time.Hour, time.Minute, time.Second) + "\tCurrent process: " + Process.GetCurrentProcess().Id.ToString()); Response.Write("<BR>"); Response.Write(String.Format("This application is running in {0}", System.Environment.Version.ToString())); System.Threading.Thread.Sleep(20000); } </script> <html> <head> <title>ASP.NET Simple Page</title> </head> <body bgcolor="#FFFFFF"> <p><asp:label id="Message" runat="server" /></p> </body> </html>
创建web.config,并把它放在sleep.aspx相同的文件夹。将最大超时时间设置为5秒。
<?xml version="1.0" encoding="UTF-8"?> <configuration> <system.web> <httpRuntime executionTimeout="5"/> </system.web> </configuration>
使用浏览器访问sleep.aspx,过一会就是收到页面报错"[HttpException (0x80004005): Request timed out.]"。警告也将纪录在应用程序事件日志中。
注:
你可能会注意到,错误消息并非在5秒钟后马上出现。因为内部 ASP.NET 使用一个计时器(System.Threading.Timer)来调用请求取消该线程执行。计时器触每15秒发一次。因此在现实中请求可能在5秒到20秒之间的任何时候超时。
详细信息可以参考http://blogs.msdn.com/b/pedram/archive/2007/10/02/how-the-execution-timeout-is-managed-in-asp-net.aspx