HttpException未被捕获

时间:2012-08-30 20:48:42

标签: c# asp.net .net sql-server-2005 iis-6

我有这个例外:

Server Error in '/datalab' Application.

Request timed out.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.Web.HttpException: Request timed out.

Source Error: 

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace: 


[HttpException (0x80004005): Request timed out.]

但我在我的/ datalab和/ datalab / powerstats目录中添加了一个Global.asax文件(datalab目录是根目录,而超时的页面是datalab / powerstats / output.aspx):

<%@ Application Language="C#" %>

<script runat="server">



void Application_Error(object sender, EventArgs e) 
{ 
    Exception exc = Server.GetLastError();

  // Handle HTTP errors
  if (exc.GetType() == typeof(HttpException))
  {
  Response.Write("<h2>Global Page Error</h2>\n");

        // The Complete Error Handling Example generates
        // some errors using URLs with "NoCatch" in them;
        // ignore these here to simulate what would happen
        // if a global.asax handler were not implemented.
        if (exc.Message.Contains("NoCatch") || exc.Message.Contains("maxUrlLength"))
            return;

        //Redirect HTTP errors to HttpError page
        //Server.Transfer("HttpErrorPage.aspx");
        return;
    }


}



</script>

如何捕获此异常?为什么不被劫持?

2 个答案:

答案 0 :(得分:1)

发生未处理的异常时会调用Application_Error事件。

由于内部服务器错误500响应已发送到客户端,因此您无法返回并更改响应。

您的问题的答案是修复超时的原因,或以编程方式增加超时时间。要在web.config中执行此操作,请尝试添加:

<httpRuntime executionTimeout="<numOfSeconds>" />

请参阅http://msdn.microsoft.com/en-us/library/e1f13641(v=vs.71).aspx

答案 1 :(得分:0)

您之前是否使用过堆栈跟踪?

查找有关如何使用它们的MSDN文档。它们具有不同类型的堆栈跟踪,具体取决于您的应用程序。